Skip to content

Commit

Permalink
Fix dialog corrupts rendering by pushing up input line too much (#524)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
tompng and st0012 authored May 7, 2023
1 parent 6cee9fa commit bc0e3d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
10 changes: 8 additions & 2 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,16 @@ def add_dialog_proc(name, p, context = nil)
# Clear and rerender all dialogs line by line
Reline::IOGate.hide_cursor
ymin, ymax = (ranges_to_restore.keys + new_dialog_ranges.keys).minmax
scroll_partial_screen = @scroll_partial_screen || 0
screen_y_range = scroll_partial_screen..(scroll_partial_screen + @screen_height - 1)
ymin = ymin.clamp(screen_y_range.begin, screen_y_range.end)
ymax = ymax.clamp(screen_y_range.begin, screen_y_range.end)
dialog_y = @first_line_started_from + @started_from
cursor_y = dialog_y
scroll_down(ymax - cursor_y)
move_cursor_up(ymax - cursor_y)
if @highest_in_all < ymax
scroll_down(ymax - cursor_y)
move_cursor_up(ymax - cursor_y)
end
(ymin..ymax).each do |y|
move_cursor_down(y - cursor_y)
cursor_y = y
Expand Down
20 changes: 17 additions & 3 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,20 @@ def test_simple_dialog_at_right_edge
EOC
end

def test_simple_dialog_with_scroll_screen
start_terminal(5, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple}, startup_message: 'Multiline REPL.')
write("if 1\n 2\n 3\n 4\n 5\n 6")
write("\C-p\C-n\C-p\C-p\C-p#")
close
assert_screen(<<~'EOC')
prompt> 2
prompt> 3#
prompt> 4
prompt> 5
prompt> 6 Ruby is...
EOC
end

def test_autocomplete_at_bottom
start_terminal(15, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.')
write('def hoge' + "\C-m" * 10 + "end\C-p ")
Expand Down Expand Up @@ -1360,12 +1374,12 @@ def test_scroll_at_bottom_for_dialog
prompt>
prompt>
prompt>
prompt> S
prompt> String
prompt> Struct
prompt> Symbol
prompt> enScriptError
prompt> enSymbol
ScriptError
SyntaxError
Signal
EOC
end

Expand Down

0 comments on commit bc0e3d1

Please sign in to comment.