From: Christian Heller Date: Sun, 19 Oct 2025 04:48:10 +0000 (+0200) Subject: Fix scrolling's .history_idx_neg calculation stumbling over bookmark line. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%27%29?a=commitdiff_plain;h=2fa8a84aa11c41d246ff2f84badbf3e883be0785;p=ircplom Fix scrolling's .history_idx_neg calculation stumbling over bookmark line. --- diff --git a/src/ircplom/tui_base.py b/src/ircplom/tui_base.py index 7ec6c46..3ebf673 100644 --- a/src/ircplom/tui_base.py +++ b/src/ircplom/tui_base.py @@ -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):