summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-11-08 21:56:27 +0900
committeraycabta <aycabta@gmail.com>2020-12-05 02:58:58 +0900
commit9750c27afc99034960b74e8951718ca07cc353a8 (patch)
treeae96e40e00356d2c0f459e9aace599fe5be63996
parentba8e5f77eb2562cc0605f1414426a34c7e844964 (diff)
[ruby/reline] Call process_insert when the end of pasting plural fullwidth chars
https://github.com/ruby/reline/commit/594484d9f9
-rw-r--r--lib/reline/general_io.rb16
-rw-r--r--lib/reline/line_editor.rb2
-rw-r--r--test/reline/helper.rb9
-rw-r--r--test/reline/test_key_actor_vi.rb22
-rw-r--r--test/reline/yamatanooroti/test_rendering.rb24
5 files changed, 72 insertions, 1 deletions
diff --git a/lib/reline/general_io.rb b/lib/reline/general_io.rb
index 3b40888bed..01a592e038 100644
--- a/lib/reline/general_io.rb
+++ b/lib/reline/general_io.rb
@@ -1,6 +1,10 @@
require 'timeout'
class Reline::GeneralIO
+ def self.reset
+ @@pasting = false
+ end
+
def self.encoding
RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
end
@@ -67,8 +71,18 @@ class Reline::GeneralIO
def self.set_winch_handler(&handler)
end
+ @@pasting = false
+
def self.in_pasting?
- false
+ @@pasting
+ end
+
+ def self.start_pasting
+ @@pasting = true
+ end
+
+ def self.finish_pasting
+ @@pasting = false
end
def self.prep
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index f9ef980cf4..10ce208e93 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -1161,6 +1161,8 @@ class Reline::LineEditor
if Reline::IOGate.in_pasting?
@continuous_insertion_buffer << str
return
+ elsif not @continuous_insertion_buffer.empty?
+ process_insert
end
width = Reline::Unicode.get_mbchar_width(str)
if @cursor == @cursor_max
diff --git a/test/reline/helper.rb b/test/reline/helper.rb
index 0b5b8af310..5593b0a602 100644
--- a/test/reline/helper.rb
+++ b/test/reline/helper.rb
@@ -7,6 +7,7 @@ module Reline
def test_mode
remove_const('IOGate') if const_defined?('IOGate')
const_set('IOGate', Reline::GeneralIO)
+ Reline::GeneralIO.reset
send(:core).config.instance_variable_set(:@test_mode, true)
send(:core).config.reset
end
@@ -17,6 +18,14 @@ module Reline
end
end
+def start_pasting
+ Reline::GeneralIO.start_pasting
+end
+
+def finish_pasting
+ Reline::GeneralIO.finish_pasting
+end
+
RELINE_TEST_ENCODING ||=
if ENV['RELINE_TEST_ENCODING']
Encoding.find(ENV['RELINE_TEST_ENCODING'])
diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb
index 7c0eea1fa1..fb7c8042ea 100644
--- a/test/reline/test_key_actor_vi.rb
+++ b/test/reline/test_key_actor_vi.rb
@@ -1353,4 +1353,26 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase
assert_cursor(0)
assert_cursor_max(3)
end
+
+ def test_pasting
+ start_pasting
+ input_keys('ab')
+ finish_pasting
+ input_keys('c')
+ assert_line('abc')
+ assert_byte_pointer_size('abc')
+ assert_cursor(3)
+ assert_cursor_max(3)
+ end
+
+ def test_pasting_fullwidth
+ start_pasting
+ input_keys('あ')
+ finish_pasting
+ input_keys('い')
+ assert_line('あい')
+ assert_byte_pointer_size('あい')
+ assert_cursor(4)
+ assert_cursor_max(4)
+ end
end
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index 2cee62e0b8..8bd72db4ba 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -62,6 +62,30 @@ begin
EOC
end
+ def test_fullwidth
+ start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
+ write(":あ\n")
+ close
+ assert_screen(<<~EOC)
+ Multiline REPL.
+ prompt> :あ
+ => :あ
+ prompt>
+ EOC
+ end
+
+ def test_two_fullwidth
+ start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
+ write(":あい\n")
+ close
+ assert_screen(<<~EOC)
+ Multiline REPL.
+ prompt> :あい
+ => :あい
+ prompt>
+ EOC
+ end
+
def test_finish_autowrapped_line
start_terminal(10, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
write("[{'user'=>{'email'=>'a@a', 'id'=>'ABC'}, 'version'=>4, 'status'=>'succeeded'}]\n")