diff options
author | tompng <[email protected]> | 2022-10-24 04:57:27 +0900 |
---|---|---|
committer | git <[email protected]> | 2023-01-18 14:49:28 +0000 |
commit | a712f2a2a0846ffbac50bfa8cd8a66a6007948db (patch) | |
tree | 141bd017a600656009e0d74d8f2dc6c0e440b9e3 /lib/reline | |
parent | 4fa7d3832427ad5133838bc97be7ab2e4e832f70 (diff) |
[ruby/reline] Fix dialog scrollbar rendering position and disappearing bug
https://github.com/ruby/reline/commit/e21b69ade4
Diffstat (limited to 'lib/reline')
-rw-r--r-- | lib/reline/line_editor.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 28daae8884..9a03903d14 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -705,17 +705,17 @@ class Reline::LineEditor dialog.scroll_top = dialog.pointer end pointer = dialog.pointer - dialog.scroll_top + else + dialog.scroll_top = 0 end dialog.contents = dialog.contents[dialog.scroll_top, height] end - if dialog.contents and dialog.scroll_top >= dialog.contents.size - dialog.scroll_top = dialog.contents.size - height - end if dialog_render_info.scrollbar and dialog_render_info.contents.size > height bar_max_height = height * 2 moving_distance = (dialog_render_info.contents.size - height) * 2 position_ratio = dialog.scroll_top.zero? ? 0.0 : ((dialog.scroll_top * 2).to_f / moving_distance) bar_height = (bar_max_height * ((dialog.contents.size * 2).to_f / (dialog_render_info.contents.size * 2))).floor.to_i + bar_height = 1 if bar_height.zero? dialog.scrollbar_pos = ((bar_max_height - bar_height) * position_ratio).floor.to_i else dialog.scrollbar_pos = nil @@ -757,7 +757,7 @@ class Reline::LineEditor str_width = dialog.width - (dialog.scrollbar_pos.nil? ? 0 : @block_elem_width) str = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, str_width), str_width) @output.write "\e[#{bg_color}m\e[#{fg_color}m#{str}" - if dialog.scrollbar_pos and (dialog.scrollbar_pos != old_dialog.scrollbar_pos or dialog.column != old_dialog.column) + if dialog.scrollbar_pos @output.write "\e[37m" if dialog.scrollbar_pos <= (i * 2) and (i * 2 + 1) < (dialog.scrollbar_pos + bar_height) @output.write @full_block |