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 wrong byte_pointer passed to auto_indent_proc #562

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

tompng
Copy link
Member

@tompng tompng commented Jul 5, 2023

Fixes byte_pointer passed to auto_indent_proc when inserting newline.
If there is multiline character, wrong byte_pointer causes invalid byte sequence error.

Fixes #553 and ruby/irb#627

@@ -1645,7 +1645,7 @@ def call_completion_proc_with_checking_args(pre, target, post)
@line = ' ' * new_indent + @line.lstrip

new_indent = nil
result = @auto_indent_proc.(new_lines[0..-2], @line_index - 1, (new_lines[-2].size + 1), false)
result = @auto_indent_proc.(new_lines[0..-2], @line_index - 1, (new_lines[@line_index - 1].bytesize + 1), false)
Copy link
Member Author

Choose a reason for hiding this comment

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

Third arg is a byte_pointer, so it should use bytesize instead of size

I think the intention of this line is to pass line_number and new_lines[line_number].bytesize + 1.
But new_lines[-2] was not always new_lines[@line_index - 1]. Fixed the index.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation! Would you mind extracting these arguments into local variables so they'd be self-documenting?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can I let it as is?
It would be readable if it is assigned to local variable, but I have problem with naming.

prev_line_index = @line_index - 1
prev_line = lines[prev_line_index]

This seems good, but there is @previous_line_index with probably different meaning. I don't have alternate idea that is not confusing.

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. Let's keep it as it is then 👍

Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

👍

@@ -1645,7 +1645,7 @@ def call_completion_proc_with_checking_args(pre, target, post)
@line = ' ' * new_indent + @line.lstrip

new_indent = nil
result = @auto_indent_proc.(new_lines[0..-2], @line_index - 1, (new_lines[-2].size + 1), false)
result = @auto_indent_proc.(new_lines[0..-2], @line_index - 1, (new_lines[@line_index - 1].bytesize + 1), false)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation! Would you mind extracting these arguments into local variables so they'd be self-documenting?

@st0012 st0012 added the bug Something isn't working label Jul 5, 2023
@st0012 st0012 merged commit 4348354 into ruby:master Jul 5, 2023
@tompng tompng deleted the fix_auto_indent_bytepointer branch July 8, 2023 11:57
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.

Inconsistent auto_indent_proc call
2 participants