From a712f2a2a0846ffbac50bfa8cd8a66a6007948db Mon Sep 17 00:00:00 2001 From: tompng Date: Mon, 24 Oct 2022 04:57:27 +0900 Subject: [PATCH] [ruby/reline] Fix dialog scrollbar rendering position and disappearing bug https://github.com/ruby/reline/commit/e21b69ade4 --- lib/reline/line_editor.rb | 8 ++++---- 1 file 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