summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2024-04-04 00:36:17 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2024-04-04 17:18:47 +0900
commit80e31663f399a1fe106fff0fffb9e222e37a037d (patch)
tree5dde9aadbed3848fa3d42054c30492ff7d233341
parent6d82be499b468242214ad701f6f86c5c60c01662 (diff)
[ruby/reline] Fix audoindent including "\v", escape "\v" for
rendering (https://github.com/ruby/reline/pull/648) https://github.com/ruby/reline/commit/9c51c577ca
-rw-r--r--lib/reline/line_editor.rb9
-rw-r--r--test/reline/yamatanooroti/test_rendering.rb14
2 files changed, 19 insertions, 4 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index d5c158ac74..1fcf5e0358 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -794,7 +794,7 @@ class Reline::LineEditor
if after = @output_modifier_proc&.call("#{before.join("\n")}\n", complete: complete)
after.lines("\n").map { |l| l.chomp('') }
else
- before
+ before.map { |l| Reline::Unicode.escape_for_print(l) }
end
end
@@ -1221,10 +1221,11 @@ class Reline::LineEditor
new_indent = @auto_indent_proc.(@buffer_of_lines.take(line_index + 1).push(''), line_index, byte_pointer, add_newline)
return unless new_indent
- @buffer_of_lines[line_index] = ' ' * new_indent + line.lstrip
+ new_line = ' ' * new_indent + line.lstrip
+ @buffer_of_lines[line_index] = new_line
if @line_index == line_index
- old_indent = line[/\A */].size
- @byte_pointer = [@byte_pointer + new_indent - old_indent, 0].max
+ indent_diff = new_line.bytesize - line.bytesize
+ @byte_pointer = [@byte_pointer + indent_diff, 0].max
end
end
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index 53c842a04a..3409b8905c 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -831,6 +831,20 @@ begin
EOC
end
+ def test_auto_indent_with_various_spaces
+ start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.')
+ write "(\n\C-v"
+ write "\C-k\n\C-v"
+ write "\C-k)"
+ close
+ assert_screen(<<~EOC)
+ Multiline REPL.
+ prompt> (
+ prompt> ^K
+ prompt> )
+ EOC
+ end
+
def test_autowrap_in_the_middle_of_a_line
start_terminal(5, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("def abcdefg; end\C-b\C-b\C-b\C-b\C-b")