From 523fb6df423743758e77178cf7c95d98e08c3197 Mon Sep 17 00:00:00 2001 From: tompng Date: Sat, 18 Mar 2023 16:32:07 +0900 Subject: [PATCH 1/3] Do not render dialog where it overflows screen --- lib/reline/line_editor.rb | 3 +++ test/reline/yamatanooroti/test_rendering.rb | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 15c3e0b1bf..5a90c3f5d2 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -708,6 +708,9 @@ 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 + screen_y_range = (@scroll_partial_screen || 0)..(@scroll_partial_screen || 0) + @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) diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 49d8ed406e..9c6a587005 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -1360,12 +1360,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 From 3206d10c5c5012e48a36f420e2d3407a5b643136 Mon Sep 17 00:00:00 2001 From: tompng Date: Sat, 18 Mar 2023 22:39:14 +0900 Subject: [PATCH 2/3] Dialog rendering should Scroll down only when needed --- lib/reline/line_editor.rb | 6 ++++-- test/reline/yamatanooroti/test_rendering.rb | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 5a90c3f5d2..d9b2b5c547 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -713,8 +713,10 @@ def add_dialog_proc(name, p, context = nil) 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 diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 9c6a587005..fce8f7474e 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -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 ") From e281afac33ec9c9f67dfc9faedd6ce9f5168de9b Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Mon, 1 May 2023 23:38:25 +0900 Subject: [PATCH 3/3] Refactor screen_y_range calculation Co-authored-by: Stan Lo --- lib/reline/line_editor.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index d9b2b5c547..b6304bc040 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -708,7 +708,8 @@ 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 - screen_y_range = (@scroll_partial_screen || 0)..(@scroll_partial_screen || 0) + @screen_height - 1 + 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