Skip to content

Commit e21b69a

Browse files
committed
Fix dialog scrollbar rendering position and disappearing bug
1 parent d00896a commit e21b69a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/reline/line_editor.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -703,17 +703,17 @@ def add_dialog_proc(name, p, context = nil)
703703
dialog.scroll_top = dialog.pointer
704704
end
705705
pointer = dialog.pointer - dialog.scroll_top
706+
else
707+
dialog.scroll_top = 0
706708
end
707709
dialog.contents = dialog.contents[dialog.scroll_top, height]
708710
end
709-
if dialog.contents and dialog.scroll_top >= dialog.contents.size
710-
dialog.scroll_top = dialog.contents.size - height
711-
end
712711
if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
713712
bar_max_height = height * 2
714713
moving_distance = (dialog_render_info.contents.size - height) * 2
715714
position_ratio = dialog.scroll_top.zero? ? 0.0 : ((dialog.scroll_top * 2).to_f / moving_distance)
716715
bar_height = (bar_max_height * ((dialog.contents.size * 2).to_f / (dialog_render_info.contents.size * 2))).floor.to_i
716+
bar_height = 1 if bar_height.zero?
717717
dialog.scrollbar_pos = ((bar_max_height - bar_height) * position_ratio).floor.to_i
718718
else
719719
dialog.scrollbar_pos = nil
@@ -755,7 +755,7 @@ def add_dialog_proc(name, p, context = nil)
755755
str_width = dialog.width - (dialog.scrollbar_pos.nil? ? 0 : @block_elem_width)
756756
str = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, str_width), str_width)
757757
@output.write "\e[#{bg_color}m\e[#{fg_color}m#{str}"
758-
if dialog.scrollbar_pos and (dialog.scrollbar_pos != old_dialog.scrollbar_pos or dialog.column != old_dialog.column)
758+
if dialog.scrollbar_pos
759759
@output.write "\e[37m"
760760
if dialog.scrollbar_pos <= (i * 2) and (i * 2 + 1) < (dialog.scrollbar_pos + bar_height)
761761
@output.write @full_block

0 commit comments

Comments
 (0)