Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bracketed paste and scrolling bug #801

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tompng
Copy link
Member

@tompng tompng commented Jan 2, 2025

Reproduce

Pasting 10 lines of code into terminal with screen height = 5

Actual screen (Reline 0.6.0)
irb(main):001> 1.tap do
irb(main):002>   2
irb(main):003>   3 
irb(main):004>   4
irb(main):005>   5█

Expected screen (Reline <= 0.5.12)
irb(main):006>   6
irb(main):007>   7
irb(main):008>   8 
irb(main):009>   9
irb(main):010> end█
  1. If you press Ctrl+C, irb crashes with the error below. Pressing other key will update the screen to the expected result.
/Users/tomoya.ishida/.rbenv/versions/3.4.1/lib/ruby/3.4.0/reline/io/ansi.rb:289:in 'String#*': negative argument (ArgumentError)

    write "\n" * x
                 ^
	from /Users/tomoya.ishida/.rbenv/versions/3.4.1/lib/ruby/3.4.0/reline/io/ansi.rb:289:in 'Reline::ANSI#scroll_down'
	from /Users/tomoya.ishida/.rbenv/versions/3.4.1/lib/ruby/3.4.0/reline/line_editor.rb:192:in 'Reline::LineEditor#handle_interrupted'
	from /Users/tomoya.ishida/.rbenv/versions/3.4.1/lib/ruby/3.4.0/reline/line_editor.rb:169:in 'Reline::LineEditor#handle_signal'

Reason

# Set pasting=true because the content of bracketed_paste is not read from stdin
line_editor.set_pasting_state(io_gate.in_pasting?)

inputs.each do |key| # inputs.size is always 1 if you don't have custom .inputrc file
  ...
  key = Reline::Key.new(io_gate.read_bracketed_paste, :insert_multiline_text) # everything is all read from stdin
  ...
  # Calls update with pasting state = true. In this case, scroll_into_view is skipped (Bug1)
  line_editor.update(key)
end

# set pasting state to false
line_editor.set_pasting_state(io_gate.in_pasting?)
# renders the screen with cursor out of the screen. rendered_screen.cursor_y will be larger than screen height (Bug2)
line_editor.rerender

Fixes

Bug1: scroll_into_view wrongly skipped, is fixed by the change in lib/reline.rb
Bug2: Fixed in lib/line_editor.rb, in case of other unknown bug that cause calling render with cursor position out of the screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant