From 5eca327fc50bebb06c6af103d109a1fef0895605 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Sun, 7 May 2023 22:18:09 +0900 Subject: [ruby/reline] Fix dialog corrupts rendering by pushing up input line too much (https://github.com/ruby/reline/pull/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 --------- https://github.com/ruby/reline/commit/bc0e3d1310 Co-authored-by: Stan Lo --- lib/reline/line_editor.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 15c3e0b1bf..b6304bc040 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -708,10 +708,16 @@ class Reline::LineEditor # 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 -- cgit v1.2.3