[pyzo] 17/68: Editor window will scroll (center the cursor) only when the cursor moves close to the window border.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Sep 28 09:47:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository pyzo.

commit a6a714e16f62c04eb43c13c438778c624a8becaa
Author: Lukas Cerman <lcerman at users.noreply.github.com>
Date:   Tue Aug 2 22:50:14 2016 +0200

    Editor window will scroll (center the cursor) only when the cursor moves close to the window border.
---
 pyzo/codeeditor/base.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/pyzo/codeeditor/base.py b/pyzo/codeeditor/base.py
index 59bc7e1..6d581a0 100644
--- a/pyzo/codeeditor/base.py
+++ b/pyzo/codeeditor/base.py
@@ -662,7 +662,15 @@ class CodeEditorBase(QtGui.QPlainTextEdit):
             self.setTextCursor(cursor)
         except Exception:
             pass # File is smaller then the caller thought
-        self.centerCursor()
+
+        # TODO make this user configurable (setting relativeMargin to anything above
+        # 0.5 will cause cursor to center on each move)
+        relativeMargin = 0.2    # 20% margin on both sides of the window
+        margin = self.height() * relativeMargin
+        cursorRect = self.cursorRect(cursor)
+        if cursorRect.top() < margin or cursorRect.bottom() + margin > self.height():
+            self.centerCursor()
+
     
     def doForSelectedBlocks(self, function):
         """ doForSelectedBlocks(function)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pyzo.git



More information about the debian-science-commits mailing list