From 737e4cdbd35cd23ad2e747bbbfad44cd6a176698 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 27 Jul 2023 08:40:19 +0530 Subject: [PATCH] unicode_input kitten: Fix scrolling over multiple screens not working Fixes #6497 --- docs/changelog.rst | 2 ++ kittens/unicode_input/table.go | 48 ++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index c4ea959bb..87ff13afb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -44,6 +44,8 @@ Detailed list of changes - Detect .tex and Makefiles as plain text files (:iss:`6492`) +- unicode_input kitten: Fix scrolling over multiple screens not working (:iss:`6497`) + 0.29.1 [2023-07-17] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/unicode_input/table.go b/kittens/unicode_input/table.go index f73b3739f..904bc08f1 100644 --- a/kittens/unicode_input/table.go +++ b/kittens/unicode_input/table.go @@ -51,15 +51,21 @@ func ljust(s string, sz int) string { return s } +type scroll_data struct { + num_items_per_page int + scroll_rows int +} + type table struct { - emoji_variation string - layout_dirty bool - last_rows, last_cols int - codepoints []rune - current_idx, scroll_rows int - text string - num_cols, num_rows int - mode Mode + emoji_variation string + layout_dirty bool + last_rows, last_cols int + codepoints []rune + current_idx int + scroll_data scroll_data + text string + num_cols, num_rows int + mode Mode green, reversed, intense_gray func(...any) string } @@ -81,6 +87,7 @@ func (self *table) current_codepoint() rune { } func (self *table) set_codepoints(codepoints []rune, mode Mode, current_idx int) { + delta := len(codepoints) - len(self.codepoints) self.codepoints = codepoints if self.codepoints != nil && mode != FAVORITES && mode != HEX { slices.Sort(self.codepoints) @@ -93,7 +100,9 @@ func (self *table) set_codepoints(codepoints []rune, mode Mode, current_idx int) if self.current_idx >= len(self.codepoints) { self.current_idx = 0 } - self.scroll_rows = 0 + if delta != 0 { + self.scroll_data = scroll_data{} + } } func (self *table) codepoint_at_hint(hint string) rune { @@ -201,7 +210,10 @@ func (self *table) layout(rows, cols int) string { space_for_desc = col_width - 2 - idx_size - 4 self.num_rows = rows rows_left := rows - skip_scroll := self.scroll_rows * self.num_cols + if self.scroll_data.num_items_per_page != self.num_cols*self.num_rows { + self.update_scroll_data() + } + skip_scroll := self.scroll_data.scroll_rows * self.num_cols for i, cd := range parts { if skip_scroll > 0 { @@ -223,6 +235,12 @@ func (self *table) layout(rows, cols int) string { return self.text } +func (self *table) update_scroll_data() { + self.scroll_data.num_items_per_page = self.num_rows * self.num_cols + page_num := self.current_idx / self.scroll_data.num_items_per_page + self.scroll_data.scroll_rows = self.num_rows * page_num +} + func (self *table) move_current(rows, cols int) { if len(self.codepoints) == 0 { return @@ -237,13 +255,5 @@ func (self *table) move_current(rows, cols int) { self.current_idx = utils.Max(0, utils.Min(self.current_idx, len(self.codepoints)-1)) self.layout_dirty = true } - first_visible := self.scroll_rows * self.num_cols - last_visible := first_visible + ((self.num_cols * self.num_rows) - 1) - scroll_amount := self.num_rows - if self.current_idx < first_visible { - self.scroll_rows = utils.Max(self.scroll_rows-scroll_amount, 0) - } - if self.current_idx > last_visible { - self.scroll_rows += scroll_amount - } + self.update_scroll_data() }