summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-01-06 03:50:19 +0900
committeraycabta <aycabta@gmail.com>2021-01-08 13:25:18 +0900
commit01235f800f953cf5c3410d7eab3744c5fa6156e9 (patch)
treeb4bece41c730a2ebe7216175983602a52671da3d
parent76c9a3c8c633241c86024a027a644f1dd6dbbc44 (diff)
[ruby/reline] Suppress auto indent for adding newlines in pasting
Co-authored-by: Juanito Fatas <me@juanitofatas.com> https://github.com/ruby/reline/commit/074bb017a7
-rw-r--r--lib/reline/line_editor.rb2
-rw-r--r--test/reline/yamatanooroti/test_rendering.rb15
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 65004cad18..31211cda33 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -1339,7 +1339,7 @@ class Reline::LineEditor
cursor_line = @line.byteslice(0, @byte_pointer)
insert_new_line(cursor_line, next_line)
@cursor = 0
- @check_new_auto_indent = true
+ @check_new_auto_indent = true unless Reline::IOGate.in_pasting?
end
end
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index 9c8df1f215..f4a5919b6c 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -663,6 +663,21 @@ begin
EOC
end
+ def test_suppress_auto_indent_for_adding_newlines_in_pasting
+ start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.')
+ write("<<~Q\n")
+ write("{\n #\n}")
+ write("#")
+ close
+ assert_screen(<<~EOC)
+ Multiline REPL.
+ prompt> <<~Q
+ prompt> {
+ prompt> #
+ prompt> }#
+ EOC
+ end
+
private def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f|
f.write content