Skip to content

Commit a925ff4

Browse files
committed
Dialog rendering should Scroll down only when needed
1 parent 7760c43 commit a925ff4

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
@@ -916,6 +916,20 @@ def test_simple_dialog_at_right_edge
916916
EOC
917917
end
918918

919+
def test_simple_dialog_with_scroll_screen
920+
start_terminal(5, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple}, startup_message: 'Multiline REPL.')
921+
write("if 1\n 2\n 3\n 4\n 5\n 6")
922+
write("\C-p\C-n\C-p\C-p\C-p#")
923+
close
924+
assert_screen(<<~'EOC')
925+
prompt> 2
926+
prompt> 3#
927+
prompt> 4
928+
prompt> 5
929+
prompt> 6 Ruby is...
930+
EOC
931+
end
932+
919933
def test_autocomplete_at_bottom
920934
start_terminal(15, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.')
921935
write('def hoge' + "\C-m" * 10 + "end\C-p ")

0 commit comments

Comments
 (0)