Skip to content

Commit cc585ee

Browse files
committed
Dialog rendering should Scroll down only when needed
1 parent dbfe077 commit cc585ee

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/reline/line_editor.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,10 @@ def add_dialog_proc(name, p, context = nil)
719719
ymax = ymax.clamp(screen_y_range.begin, screen_y_range.end)
720720
dialog_y = @first_line_started_from + @started_from
721721
cursor_y = dialog_y
722-
scroll_down(ymax - cursor_y)
723-
move_cursor_up(ymax - cursor_y)
722+
if @highest_in_all < ymax
723+
scroll_down(ymax - cursor_y)
724+
move_cursor_up(ymax - cursor_y)
725+
end
724726
(ymin..ymax).each do |y|
725727
move_cursor_down(y - cursor_y)
726728
cursor_y = y

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,20 @@ def test_simple_dialog_at_right_edge
957957
EOC
958958
end
959959

960+
def test_simple_dialog_with_scroll_screen
961+
start_terminal(5, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple}, startup_message: 'Multiline REPL.')
962+
write("if 1\n 2\n 3\n 4\n 5\n 6")
963+
write("\C-p\C-n\C-p\C-p\C-p#")
964+
close
965+
assert_screen(<<~'EOC')
966+
prompt> 2
967+
prompt> 3#
968+
prompt> 4
969+
prompt> 5
970+
prompt> 6 Ruby is...
971+
EOC
972+
end
973+
960974
def test_autocomplete_at_bottom
961975
start_terminal(15, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.')
962976
write('def hoge' + "\C-m" * 10 + "end\C-p ")

0 commit comments

Comments
 (0)