home · contact · privacy
On prompt history scroll, move cursor to end of retrieved record.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 11 Jun 2025 13:06:22 +0000 (15:06 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 11 Jun 2025 13:06:22 +0000 (15:06 +0200)
ircplom.py

index 83870d17421ef8bb3cddebda07e23f4d37d24f16..228027699b07db40171f8c3303c5e63f5d37e6dd 100755 (executable)
@@ -542,6 +542,7 @@ class PromptWidget(ScrollableWidget):
     _width: int
     _prompt: str = PROMPT_TEMPLATE
     _history_idx = 0
+    _cursor_x: int
 
     def __init__(self, *args, **kwargs) -> None:
         super().__init__(*args, **kwargs)
@@ -588,20 +589,25 @@ class PromptWidget(ScrollableWidget):
         self._write(to_write[cursor_x_to_write + 1:])
 
     def _scroll(self, up: bool = True) -> None:
+
+        def set_to_record_at_idx() -> None:
+            self._input_buffer = self._history[self._history_idx][:]
+            self._cursor_x = len(self._input_buffer) + 1
+
         if up and -(self._history_idx) < len(self._history):
             if self._history_idx == 0 and self._input_buffer:
                 self._history += [self._input_buffer[:]]
                 self._clear()
                 self._history_idx -= 1
             self._history_idx -= 1
-            self._input_buffer = self._history[self._history_idx][:]
+            set_to_record_at_idx()
         elif not up:
             if self._history_idx < 0:
                 self._history_idx += 1
                 if self._history_idx == 0:
                     self._clear()
                 else:
-                    self._input_buffer = self._history[self._history_idx][:]
+                    set_to_record_at_idx()
             elif self._input_buffer:
                 self._history += [self._input_buffer[:]]
                 self._clear()