Skip to content

Commit d6b8d24

Browse files
committed
filediff: Fix race condition on scrolling to first chunk (bgo#780625)
When we load a comparison, we scroll to the first difference. If the first difference is on the first line of the file, we hit a race condition (though reliably triggerable in some cases) where we set the `next` attribute of our cursor and schedule a go_to_chunk on it, but then our cursor changed callback kicks in and re-sets the `next` attribute, causing us to go to the *second* difference. There's no obvious reason why we need to set the cursor chunk here. History vaguely suggests that it's because we weren't getting cursor callbacks, so set up the necessary state manually. However, we can just pass the actual chunk we have decided we want to go to, instead of modifying the cursor itself, which seems a lot safer.
1 parent f8d3814 commit d6b8d24

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

meld/filediff.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,17 +1109,13 @@ def _diff_files(self, refresh=False):
11091109
yield 1
11101110

11111111
if not refresh:
1112-
chunk, prev, next_ = self.linediffer.locate_chunk(1, 0)
1113-
self.cursor.next = chunk
1114-
if self.cursor.next is None:
1115-
self.cursor.next = next_
11161112
for buf in self.textbuffer:
11171113
buf.place_cursor(buf.get_start_iter())
11181114

1119-
if self.cursor.next is not None:
1120-
self.scheduler.add_task(
1121-
lambda: self.go_to_chunk(self.cursor.next, centered=True),
1122-
True)
1115+
chunk, prev, next_ = self.linediffer.locate_chunk(1, 0)
1116+
target_chunk = chunk if chunk is not None else next_
1117+
self.scheduler.add_task(
1118+
lambda: self.go_to_chunk(target_chunk, centered=True), True)
11231119

11241120
self.queue_draw()
11251121
self._connect_buffer_handlers()

0 commit comments

Comments
 (0)