Skip to content

Commit 12ea63e

Browse files
committed
Re-calc the scroll pos when the content in dialog is shortened
1 parent 4ecaa63 commit 12ea63e

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/reline/line_editor.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ def add_dialog_proc(name, p, context = nil)
671671
end
672672
dialog.contents = dialog.contents[dialog.scroll_top, height]
673673
end
674+
if dialog.contents and dialog.scroll_top >= dialog.contents.size
675+
dialog.scroll_top = dialog.contents.size - height
676+
end
674677
if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
675678
bar_max_height = height * 2
676679
moving_distance = (dialog_render_info.contents.size - height) * 2

test/reline/yamatanooroti/multiline_repl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ opt.on('--autocomplete-long') {
115115
}.select{ |c| c.start_with?(target) }
116116
}
117117
}
118+
opt.on('--autocomplete-super-long') {
119+
Reline.autocompletion = true
120+
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
121+
c = 'A'
122+
2000.times.map{ s = "Str_#{c}"; c.succ!; s }.select{ |c| c.start_with?(target) }
123+
}
124+
}
118125
opt.parse!(ARGV)
119126

120127
begin

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,33 @@ def test_autocomplete_long_with_scrollbar_scroll
10571057
EOC
10581058
end
10591059

1060+
def test_autocomplete_super_long_and_backspace
1061+
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-super-long}, startup_message: 'Multiline REPL.')
1062+
shift_tab = [27, 91, 90]
1063+
write('S' + shift_tab.map(&:chr).join)
1064+
write("\C-h")
1065+
close
1066+
assert_screen(<<~'EOC')
1067+
Multiline REPL.
1068+
prompt> Str_BX
1069+
Str_BX
1070+
Str_BXA
1071+
Str_BXB
1072+
Str_BXC
1073+
Str_BXD
1074+
Str_BXE
1075+
Str_BXF
1076+
Str_BXG
1077+
Str_BXH
1078+
Str_BXI
1079+
Str_BXJ
1080+
Str_BXK
1081+
Str_BXL
1082+
Str_BXM
1083+
Str_BXN
1084+
EOC
1085+
end
1086+
10601087
def test_dialog_callback_returns_nil
10611088
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog nil}, startup_message: 'Multiline REPL.')
10621089
write('a')

0 commit comments

Comments
 (0)