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 line rendering when newline is added at the end of the buffer #507

Merged
merged 1 commit into from
Feb 6, 2023

Conversation

tompng
Copy link
Member

@tompng tompng commented Jan 22, 2023

Fixed #505

When newline is added at the end of the buffer, reline re-calculates previous line indentation.
Reline needs to render both previous line and added line, but renderes only added line.
I changed rerender_added_newline to also render previous line.

@tompng
Copy link
Member Author

tompng commented Jan 23, 2023

To see which line is re-rendered, I used this snippet paste to bin/console

def (IRB::Color).colorize_code(code,**)
  code.chars.map do
    "\e[#{rand(30..37)}m#{_1}"
  end.join
end

@buffer_of_lines[@previous_line_index] = @line
@line = @buffer_of_lines[@line_index]
unless @in_pasting
@previous_line_index = nil
Copy link
Member

Choose a reason for hiding this comment

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

Why did you move this line?

Copy link
Member Author

Choose a reason for hiding this comment

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

I move it because I am using whole_lines in line 979.

In other place of line_editor.rb, whole_lines is called in this form

if @previous_line_index
  whole_lines(index: @previous_line_index, line: @line)
else
  whole_lines
end

whole_lines also depends on @buffer_of_lines, @line and @line_index. Calling whole_lines between changing these instance variables seems dangerous for me.
After moving it, @buffer_of_lines @line @previous_line_index is changed all at once.

If I don't move it, it still works but won't work after #460 is merged.

Copy link
Member

Choose a reason for hiding this comment

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

I see. I understood. Thank you for your reply.

@ima1zumi ima1zumi merged commit f15d1c5 into ruby:master Feb 6, 2023
@tompng tompng deleted the fix_add_new_line_rerender branch February 6, 2023 15:49
@ima1zumi ima1zumi added the bug Something isn't working label Mar 27, 2023
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.

Reline does not rerender previous line when inserting newline at the end of the buffer
2 participants