Skip to content

Commit bc0e3d1

Browse files
tompngst0012
andauthored
Fix dialog corrupts rendering by pushing up input line too much (#524)
* Do not render dialog where it overflows screen * Dialog rendering should Scroll down only when needed * Refactor screen_y_range calculation Co-authored-by: Stan Lo <stan001212@gmail.com> --------- Co-authored-by: Stan Lo <stan001212@gmail.com>
1 parent 6cee9fa commit bc0e3d1

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/reline/line_editor.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,16 @@ def add_dialog_proc(name, p, context = nil)
708708
# Clear and rerender all dialogs line by line
709709
Reline::IOGate.hide_cursor
710710
ymin, ymax = (ranges_to_restore.keys + new_dialog_ranges.keys).minmax
711+
scroll_partial_screen = @scroll_partial_screen || 0
712+
screen_y_range = scroll_partial_screen..(scroll_partial_screen + @screen_height - 1)
713+
ymin = ymin.clamp(screen_y_range.begin, screen_y_range.end)
714+
ymax = ymax.clamp(screen_y_range.begin, screen_y_range.end)
711715
dialog_y = @first_line_started_from + @started_from
712716
cursor_y = dialog_y
713-
scroll_down(ymax - cursor_y)
714-
move_cursor_up(ymax - cursor_y)
717+
if @highest_in_all < ymax
718+
scroll_down(ymax - cursor_y)
719+
move_cursor_up(ymax - cursor_y)
720+
end
715721
(ymin..ymax).each do |y|
716722
move_cursor_down(y - cursor_y)
717723
cursor_y = y

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 17 additions & 3 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 ")
@@ -1360,12 +1374,12 @@ def test_scroll_at_bottom_for_dialog
13601374
prompt>
13611375
prompt>
13621376
prompt>
1377+
prompt> S
13631378
prompt> String
13641379
prompt> Struct
1365-
prompt> Symbol
1366-
prompt> enScriptError
1380+
prompt> enSymbol
1381+
ScriptError
13671382
SyntaxError
1368-
Signal
13691383
EOC
13701384
end
13711385

0 commit comments

Comments
 (0)