From 8088aad4020f065f4c19eeab30751fda916d0c2e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 26 Jan 2014 16:53:07 +0530 Subject: [PATCH] Fix non-linear scrolling in the diff view --- src/calibre/gui2/tweak_book/diff/view.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/tweak_book/diff/view.py b/src/calibre/gui2/tweak_book/diff/view.py index 5c14859c86..3e84ec8dbd 100644 --- a/src/calibre/gui2/tweak_book/diff/view.py +++ b/src/calibre/gui2/tweak_book/diff/view.py @@ -823,7 +823,7 @@ class DiffView(QWidget): # {{{ @property def syncpos(self): - return self.scrollbar.value() + int(self.scrollbar.pageStep() * self.SYNC_POSITION) + return int(ceil(self.scrollbar.pageStep() * self.SYNC_POSITION)) def get_position_from_scrollbar(self, which): changes = (self.changes, self.view.left.changes, self.view.right.changes)[which] @@ -832,9 +832,12 @@ class DiffView(QWidget): # {{{ prev = (0, 0, None) for i, (top, bot, kind) in enumerate(changes): if syncpos <= bot: - if top <= syncpos and top != bot: + if top <= syncpos: # syncpos is inside a change - ratio = float(syncpos - top) / (bot - top) + try: + ratio = float(syncpos - top) / (bot - top) + except ZeroDivisionError: + ratio = 0 return 'in', i, ratio else: # syncpos is after the change @@ -850,7 +853,6 @@ class DiffView(QWidget): # {{{ def scroll_to(self, which, position): changes = (self.changes, self.view.left.changes, self.view.right.changes)[which] bar = self.bars[which] - syncpos = self.syncpos val = None if position[0] == 'in': change_idx, ratio = position[1:] @@ -860,7 +862,7 @@ class DiffView(QWidget): # {{{ change_idx, offset = position[1:] start = 0 if change_idx < 0 else changes[change_idx][1] val = start + offset - bar.setValue(val - syncpos) + bar.setValue(val - self.syncpos) def scrolled(self, which, *args): if self.syncing: