home · contact · privacy
Fix scrolling's .history_idx_neg calculation stumbling over bookmark line.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 19 Oct 2025 04:48:10 +0000 (06:48 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 19 Oct 2025 04:48:10 +0000 (06:48 +0200)
src/ircplom/tui_base.py

index 7ec6c462675c5fa8e11bf38c08df7571c45115de..3ebf6735d78cc64c48052822e9ed7b54a62e8f01 100644 (file)
@@ -222,14 +222,20 @@ class _HistoryWidget(_ScrollableWidget):
                 self._wrapped_idx_neg += 1
         if self._newest_read_history_idx_pos < self._history_offset:
             return
-        bookmark_wrapped_idx_pos = (
-                0 if (not self._wrapped)
-                else (1 + self._last_wrapped_idx_pos_for_hist_idx_pos(
-                    self._newest_read_history_idx_pos)))
-        self._wrapped.insert(bookmark_wrapped_idx_pos, bookmark)
-        if bookmark_wrapped_idx_pos - len(self._wrapped)\
-                > self._wrapped_idx_neg:
-            self._wrapped_idx_neg -= 1
+        if not self._wrapped:
+            return
+        self._wrapped.insert(self._bookmark_wrapped_idx_pos, bookmark)
+        self._wrapped_idx_neg -= int(self._bookmark_wrapped_idx_neg
+                                     > self._wrapped_idx_neg)
+
+    @property
+    def _bookmark_wrapped_idx_pos(self) -> int:
+        return self._last_wrapped_idx_pos_for_hist_idx_pos(
+                self._newest_read_history_idx_pos) + 1
+
+    @property
+    def _bookmark_wrapped_idx_neg(self) -> int:
+        return self._bookmark_wrapped_idx_pos - len(self._wrapped)
 
     def _last_wrapped_idx_pos_for_hist_idx_pos(self, hist_idx_pos: int) -> int:
         return [idx for idx, t in enumerate(self._wrapped)
@@ -257,9 +263,10 @@ class _HistoryWidget(_ScrollableWidget):
             else:
                 self._wrapped_idx_neg = min(
                         -1, self._wrapped_idx_neg + self._y_pgscroll)
-            self._history_idx_neg\
-                = (-self._len_full_history
-                   + max(0, self._wrapped[self._wrapped_idx_neg][0]))
+            idx = self._wrapped_idx_neg - int(
+                    self._wrapped_idx_neg == self._bookmark_wrapped_idx_neg)
+            self._history_idx_neg = (-self._len_full_history
+                                     + max(0, self._wrapped[idx][0]))
 
 
 class PromptWidget(_ScrollableWidget):