Browse Source

Move cursor along with selection for scrolling

Sebastian Lohff 1 year ago
parent
commit
ad3fd751cc
1 changed files with 9 additions and 4 deletions
  1. 9
    4
      clintermission/climenu.py

+ 9
- 4
clintermission/climenu.py View File

@@ -157,6 +157,10 @@ class CliMenu:
157 157
 
158 158
         while True:
159 159
             self._pos = (self._pos + direction) % len(self._items)
160
+
161
+            # move cursor of buffer along with the selected option
162
+            self._buf.cursor_position = self._doc.translate_row_col_to_index(self._pos, 0)
163
+
160 164
             if self._items[self._pos].focusable:
161 165
                 break
162 166
 
@@ -188,10 +192,6 @@ class CliMenu:
188 192
             self._success = True
189 193
             event.app.exit()
190 194
 
191
-        # set initial pos
192
-        if not self._items[self._pos].focusable:
193
-            self.next_item(1)
194
-
195 195
         text = '\n'.join(map(lambda _x: _x.text, self._items))
196 196
         self._doc = Document(text, cursor_position=self._pos)
197 197
         self._buf = Buffer(read_only=True, document=self._doc)
@@ -200,6 +200,11 @@ class CliMenu:
200 200
         split = HSplit([Window(self._bufctrl,
201 201
                                wrap_lines=True,
202 202
                                always_hide_cursor=True)])
203
+
204
+        # set initial pos
205
+        if not self._items[self._pos].focusable:
206
+            self.next_item(1)
207
+
203 208
         app = Application(layout=Layout(split),
204 209
                           key_bindings=self._kb,
205 210
                           full_screen=False,

Loading…
Cancel
Save