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 cursor position overrun #515

Merged
merged 2 commits into from Mar 27, 2023

Conversation

tompng
Copy link
Member

@tompng tompng commented Mar 9, 2023

When input lines is larget than screen height, and move cursor up and down, cursor position sometimes overruns
And if you input something, irb will crash. this pull request fixes it.
I think #470 will be fixed.

Left: before, Right: after
https://user-images.githubusercontent.com/1780201/224025150-fd53acd6-7ea1-42fc-8150-76001990518f.mp4

changes

calculate_nearest_cursor
...
update_previous_line_index
if @rerender_all
  update_line
  # forgot update_cursor_to_nearest_cursor_position
  rerender_all_lines
else
  update_line
  maybe_prepareing_instance_variables_for_moving_cursor
  update_cursor_to_nearest_cursor_position
  move_cursor
end

calculate_nearest_cursor
update_cursor_to_nearest_cursor_position
...
# updating @line, @line_index, @previous_line_index are updated at once, used together in many place in line_editor.rb
update_line_and_previous_line_index

# rendering part
if @rerender_all
  # only doing rendering here
  rerender_all_lines
else
  # only doing cursor moving(≒ cursor rendering) here
  maybe_prepareing_instance_variables_for_moving_cursor
  move_cursor
end

lib/reline/line_editor.rb Outdated Show resolved Hide resolved
Co-authored-by: Stan Lo <stan001212@gmail.com>
@st0012 st0012 added the bug Something isn't working label Mar 19, 2023
Copy link
Member

@ima1zumi ima1zumi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ima1zumi ima1zumi merged commit d4ad9b9 into ruby:master Mar 27, 2023
29 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Mar 27, 2023
(ruby/reline#515)

* Fix cursor position overrun

* Remove unnecessary local variable

Co-authored-by: Stan Lo <stan001212@gmail.com>

---------

ruby/reline@d4ad9b96c8

Co-authored-by: Stan Lo <stan001212@gmail.com>
@tompng tompng deleted the fix_cursor_overrun_on_scroll branch July 19, 2023 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

None yet

3 participants