mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure that neighboring changes of the same kind are merged
This commit is contained in:
parent
9e68f3a488
commit
5a02780254
@ -244,12 +244,25 @@ class TextDiffView(QSplitter):
|
||||
c.movePosition(c.Start)
|
||||
v.setTextCursor(c)
|
||||
|
||||
self.coalesce_changes()
|
||||
|
||||
for ltop, lbot, rtop, rbot, kind in self.changes:
|
||||
self.left.changes.append((ltop, lbot, kind))
|
||||
self.right.changes.append((rtop, rbot, kind))
|
||||
if kind != 'equal':
|
||||
self.left.changes.append((ltop, lbot, kind))
|
||||
self.right.changes.append((rtop, rbot, kind))
|
||||
|
||||
self.update()
|
||||
|
||||
def coalesce_changes(self):
|
||||
'Merge neighboring changes of the same kind, if any'
|
||||
changes = []
|
||||
for x in self.changes:
|
||||
if changes and changes[-1].kind == x.kind:
|
||||
changes[-1] = changes[-1]._replace(lbot=x.lbot, rbot=x.rbot)
|
||||
else:
|
||||
changes.append(x)
|
||||
self.changes = changes
|
||||
|
||||
def do_insert(self, cursor, highlighter, line_number_map, lo, hi):
|
||||
start_block = cursor.block()
|
||||
highlighter.copy_lines(lo, hi, cursor)
|
||||
@ -258,7 +271,10 @@ class TextDiffView(QSplitter):
|
||||
return start_block.blockNumber(), cursor.block().blockNumber()
|
||||
|
||||
def equal(self, alo, ahi, blo, bhi):
|
||||
self.left_insert(alo, ahi), self.right_insert(blo, bhi)
|
||||
lsb, lcb = self.left_insert(alo, ahi)
|
||||
rsb, rcb = self.right_insert(blo, bhi)
|
||||
self.changes.append(Change(
|
||||
rtop=rsb, rbot=rcb, ltop=lsb, lbot=lcb, kind='equal'))
|
||||
|
||||
def delete(self, alo, ahi, blo, bhi):
|
||||
start_block, current_block = self.left_insert(alo, ahi)
|
||||
|
Loading…
x
Reference in New Issue
Block a user