From c5d5c444dfb31cd8b89c5ac2cef1b5af9a27cfdd Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Sun, 5 Jan 2025 13:57:19 +0900 Subject: [PATCH] Fix bracketed paste and scrolling bug (#801) * Fix set_pasting_state bug with bracketed paste * Fix rendered cursor_y caching in case of rendering the screen without scroll_into_view --- lib/reline.rb | 3 +-- lib/reline/line_editor.rb | 1 + test/reline/yamatanooroti/test_rendering.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index 52e1e399c3..5d1fcbf8e8 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -341,7 +341,6 @@ def readline(prompt = '', add_hist = false) line_editor.set_signal_handlers loop do read_io(config.keyseq_timeout) { |inputs| - line_editor.set_pasting_state(io_gate.in_pasting?) inputs.each do |key| case key.method_symbol when :bracketed_paste_start @@ -350,6 +349,7 @@ def readline(prompt = '', add_hist = false) when :quoted_insert, :ed_quoted_insert key = Reline::Key.new(io_gate.read_single_char(config.keyseq_timeout), :insert_raw_char) end + line_editor.set_pasting_state(io_gate.in_pasting?) line_editor.update(key) end } @@ -357,7 +357,6 @@ def readline(prompt = '', add_hist = false) line_editor.render_finished break else - line_editor.set_pasting_state(io_gate.in_pasting?) line_editor.rerender end end diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 0895234aea..aa4c7facdc 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -542,6 +542,7 @@ def render Reline::IOGate.show_cursor end Reline::IOGate.move_cursor_column new_cursor_x + new_cursor_y = new_cursor_y.clamp(0, screen_height - 1) Reline::IOGate.move_cursor_down new_cursor_y - cursor_y @rendered_screen.cursor_y = new_cursor_y ensure diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 2952d3bfc8..782ad71eb9 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -550,6 +550,14 @@ def test_bracketed_paste prompt> 3 prompt> end EOC + write("\e[200~.tap do\r\t4\r\t5\rend\e[201~") + assert_screen(<<~EOC) + prompt> 3 + prompt> end.tap do + prompt> 4 + prompt> 5 + prompt> end + EOC close end