home · contact · privacy
On prompt history scroll-down, if at idx=0 on non-empty buffer, push it up into history.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 11 Jun 2025 13:00:48 +0000 (15:00 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 11 Jun 2025 13:00:48 +0000 (15:00 +0200)
ircplom.py

index a603d0ed530fdc537eb19db44a6af295c591aa67..83870d17421ef8bb3cddebda07e23f4d37d24f16 100755 (executable)
@@ -541,6 +541,7 @@ class PromptWidget(ScrollableWidget):
     _y: int
     _width: int
     _prompt: str = PROMPT_TEMPLATE
+    _history_idx = 0
 
     def __init__(self, *args, **kwargs) -> None:
         super().__init__(*args, **kwargs)
@@ -593,14 +594,17 @@ class PromptWidget(ScrollableWidget):
                 self._clear()
                 self._history_idx -= 1
             self._history_idx -= 1
-        elif (not up) and self._history_idx < 0:
-            self._history_idx += 1
-            if self._history_idx == 0:
+            self._input_buffer = self._history[self._history_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][:]
+            elif self._input_buffer:
+                self._history += [self._input_buffer[:]]
                 self._clear()
-                return
-        else:
-            return
-        self._input_buffer = self._history[self._history_idx][:]
 
     def cmd__backspace(self) -> None:
         'Truncate current content by one character, if possible.'