From: Christian Heller Date: Mon, 29 Sep 2025 05:36:14 +0000 (+0200) Subject: Fix slightly-off bookmark and scroll infos. X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=8834755781bf13c374a06ad80245b4e8a587167c;p=ircplom Fix slightly-off bookmark and scroll infos. --- diff --git a/src/ircplom/tui_base.py b/src/ircplom/tui_base.py index 3414a7d..b0a88b9 100644 --- a/src/ircplom/tui_base.py +++ b/src/ircplom/tui_base.py @@ -105,8 +105,8 @@ class _ScrollableWidget(_Widget): class _HistoryWidget(_ScrollableWidget): - _last_read: int = 0 - _bookmark: int = 0 + _last_read_idx_pos: int = 0 + _bookmark_idx_pos: int = 0 _y_pgscroll: int def __init__(self, wrap: Callable[[str], list[str]], **kwargs) -> None: @@ -153,12 +153,13 @@ class _HistoryWidget(_ScrollableWidget): start_idx_neg = self._wrapped_idx_neg - self._sizes.y + 1 end_idx_neg = self._wrapped_idx_neg idx_pos_bookmark = ([idx_pos for idx_pos, t in enumerate(self._wrapped) - if t[0] == self._bookmark]+[0])[0] - wrapped = (self._wrapped[:idx_pos_bookmark+1] - + [(0, '-'*self._sizes.x)] - + self._wrapped[idx_pos_bookmark+1:]) + if t[0] == self._bookmark_idx_pos] + [0])[0] + wrapped = (self._wrapped[:idx_pos_bookmark] + + [(0, '-' * self._sizes.x)] + + self._wrapped[idx_pos_bookmark:]) to_write = [t[1] for t in wrapped[start_idx_neg:end_idx_neg]] - if self._wrapped_idx_neg < -1: + add_scroll_info = self._wrapped_idx_neg < -1 + if add_scroll_info: scroll_info = f'vvv [{(-1) * self._wrapped_idx_neg}] ' scroll_info += 'v' * (self._sizes.x - len(scroll_info)) to_write += [scroll_info] @@ -166,17 +167,18 @@ class _HistoryWidget(_ScrollableWidget): to_write += [wrapped[self._wrapped_idx_neg][1]] for i, line in enumerate(to_write): self._write(line, i) - hist_idx_pos = self._wrapped[end_idx_neg][0] - self._last_read = max(self._last_read, hist_idx_pos or 0) + hist_idx_pos = self._wrapped[end_idx_neg - int(add_scroll_info)][0] + self._last_read_idx_pos = max(self._last_read_idx_pos, + hist_idx_pos or 0) def bookmark(self) -> None: 'Store to what most recent line we have (been) scrolled.' - self._bookmark = self._last_read + self._bookmark_idx_pos = self._last_read_idx_pos + 1 @property def n_lines_unread(self) -> int: 'How many new lines have been logged since last focus.' - return len(self._history) - self._last_read - 1 + return len(self._history) - self._last_read_idx_pos def _scroll(self, up: bool = True) -> None: super()._scroll(up)