Skip to content

Commit

Permalink
Fix wrong byte_pointer passed to auto_indent_proc (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng authored Jul 5, 2023
1 parent 45acc2f commit 4348354
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
if result
new_indent = result
end
Expand Down
18 changes: 18 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,24 @@ def test_auto_indent_when_inserting_line
EOC
end

def test_auto_indent_multibyte_insert_line
start_terminal(10, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.')
write "if true\n"
write "あいうえお\n"
4.times { write "\C-b\C-b\C-b\C-b\e\r" }
close
assert_screen(<<~EOC)
Multiline REPL.
prompt> if true
prompt> あ
prompt> い
prompt> う
prompt> え
prompt> お
prompt>
EOC
end

def test_newline_after_wrong_indent
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.')
write "if 1\n aa"
Expand Down

0 comments on commit 4348354

Please sign in to comment.