Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrollbar wrongly displayed bug #487

Merged
merged 3 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module CompletionState
MenuInfo = Struct.new('MenuInfo', :target, :list)

PROMPT_LIST_CACHE_TIMEOUT = 0.5
MINIMUM_SCROLLBAR_HEIGHT = 1

def initialize(config, encoding)
@config = config
Expand Down Expand Up @@ -703,17 +704,17 @@ def add_dialog_proc(name, p, context = nil)
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 = MINIMUM_SCROLLBAR_HEIGHT if bar_height < MINIMUM_SCROLLBAR_HEIGHT
dialog.scrollbar_pos = ((bar_max_height - bar_height) * position_ratio).floor.to_i
else
dialog.scrollbar_pos = nil
Expand Down Expand Up @@ -755,7 +756,7 @@ def add_dialog_proc(name, p, context = nil)
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
Expand Down
46 changes: 36 additions & 10 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,32 @@ def test_autocomplete_long_with_scrollbar_scroll
EOC
end

def test_autocomplete_super_long_scroll_to_bottom
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-super-long}, startup_message: 'Multiline REPL.')
shift_tab = [27, 91, 90]
write('S' + shift_tab.map(&:chr).join)
close
assert_screen(<<~'EOC')
Multiline REPL.
prompt> Str_BXX
Str_BXJ
Str_BXK
Str_BXL
Str_BXM
Str_BXN
Str_BXO
Str_BXP
Str_BXQ
Str_BXR
Str_BXS
Str_BXT
Str_BXU
Str_BXV
Str_BXW
Str_BXX▄
EOC
end

def test_autocomplete_super_long_and_backspace
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-super-long}, startup_message: 'Multiline REPL.')
shift_tab = [27, 91, 90]
Expand All @@ -1090,15 +1116,15 @@ def test_autocomplete_super_long_and_backspace
assert_screen(<<~'EOC')
Multiline REPL.
prompt> Str_BX
Str_BX
Str_BXA
Str_BXB
Str_BXC
Str_BXD
Str_BXE
Str_BXF
Str_BXG
Str_BXH
Str_BX
Str_BXA
Str_BXB
Str_BXC
Str_BXD
Str_BXE
Str_BXF
Str_BXG
Str_BXH
Str_BXI
Str_BXJ
Str_BXK
Expand Down Expand Up @@ -1142,7 +1168,7 @@ def test_dialog_narrower_than_screen_with_scrollbar
Multiline R
EPL.
prompt> Sym
String
String
Struct █
Symbol █
StopIterat█
Expand Down