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

Re-calc the scroll pos when the content in dialog is shortened #365

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
3 changes: 3 additions & 0 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ def add_dialog_proc(name, p, context = nil)
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
Expand Down
7 changes: 7 additions & 0 deletions test/reline/yamatanooroti/multiline_repl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ opt.on('--autocomplete-long') {
}.select{ |c| c.start_with?(target) }
}
}
opt.on('--autocomplete-super-long') {
Reline.autocompletion = true
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
c = 'A'
2000.times.map{ s = "Str_#{c}"; c.succ!; s }.select{ |c| c.start_with?(target) }
}
}
opt.parse!(ARGV)

begin
Expand Down
27 changes: 27 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,33 @@ def test_autocomplete_long_with_scrollbar_scroll
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]
write('S' + shift_tab.map(&:chr).join)
write("\C-h")
close
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_BXI
Str_BXJ
Str_BXK
Str_BXL
Str_BXM
Str_BXN
EOC
end

def test_dialog_callback_returns_nil
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog nil}, startup_message: 'Multiline REPL.')
write('a')
Expand Down