summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-05-19 06:41:13 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-05-19 06:59:56 +0200
commita0096e30779fc1a15ed14371999c1b423aba6e5a (patch)
tree1df2191fbd4da9b4de13b341b58aeba013a38039
parent5aad532a8d872829c25da95caf737b5270019acc (diff)
menuconfig: Implement scroll offset for text boxes
This makes it clearer when an edit box is scrolled, especially when backspacing. The cursor will now only go to the far left/right of the edit box at the start/end of the string. Reuse _SCROLL_OFFSET to specify the scroll offset.
-rwxr-xr-xmenuconfig.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/menuconfig.py b/menuconfig.py
index 78d5df6..9f6f28e 100755
--- a/menuconfig.py
+++ b/menuconfig.py
@@ -118,7 +118,8 @@ _SUBMENU_INDENT = 4
_PG_JUMP = 6
# How far the cursor needs to be from the edge of the window before it starts
-# to scroll
+# to scroll. Used for the main menu display, the information display, the
+# search display, and for text boxes.
_SCROLL_OFFSET = 5
# Minimum width of dialogs that ask for text input
@@ -2103,13 +2104,14 @@ def _edit_text(c, s, i, hscroll, width):
s = s[:i] + c + s[i:]
i += 1
-
- # Adjust the horizontal scroll if the cursor would be outside the input
- # field
- if i < hscroll:
- hscroll = i
- elif i >= hscroll + width:
- hscroll = i - width + 1
+ # Adjust the horizontal scroll so that the cursor never touches the left or
+ # right edges of the edit box, except when it's at the beginning or the end
+ # of the string
+ if i < hscroll + _SCROLL_OFFSET:
+ hscroll = max(i - _SCROLL_OFFSET, 0)
+ elif i >= hscroll + width - _SCROLL_OFFSET:
+ max_scroll = max(len(s) - width + 1, 0)
+ hscroll = min(i - width + _SCROLL_OFFSET + 1, max_scroll)
return s, i, hscroll