Skip to content

Commit

Permalink
Fix bracketed paste and scrolling bug (#801)
Browse files Browse the repository at this point in the history
* Fix set_pasting_state bug with bracketed paste

* Fix rendered cursor_y caching in case of rendering the screen without scroll_into_view
  • Loading branch information
tompng authored Jan 5, 2025
1 parent 72c0ec0 commit c5d5c44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -350,14 +349,14 @@ 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
}
if line_editor.finished?
line_editor.render_finished
break
else
line_editor.set_pasting_state(io_gate.in_pasting?)
line_editor.rerender
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c5d5c44

Please sign in to comment.