Skip to content

Commit 594484d

Browse files
committed
Call process_insert when the end of pasting plural fullwidth chars
1 parent 6ef8975 commit 594484d

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

lib/reline/general_io.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
require 'timeout'
22

33
class Reline::GeneralIO
4+
def self.reset
5+
@@pasting = false
6+
end
7+
48
def self.encoding
59
RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
610
end
@@ -67,8 +71,18 @@ def self.set_screen_size(rows, columns)
6771
def self.set_winch_handler(&handler)
6872
end
6973

74+
@@pasting = false
75+
7076
def self.in_pasting?
71-
false
77+
@@pasting
78+
end
79+
80+
def self.start_pasting
81+
@@pasting = true
82+
end
83+
84+
def self.finish_pasting
85+
@@pasting = false
7286
end
7387

7488
def self.prep

lib/reline/line_editor.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,8 @@ def finish
11611161
if Reline::IOGate.in_pasting?
11621162
@continuous_insertion_buffer << str
11631163
return
1164+
elsif not @continuous_insertion_buffer.empty?
1165+
process_insert
11641166
end
11651167
width = Reline::Unicode.get_mbchar_width(str)
11661168
if @cursor == @cursor_max

test/reline/helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class <<self
77
def test_mode
88
remove_const('IOGate') if const_defined?('IOGate')
99
const_set('IOGate', Reline::GeneralIO)
10+
Reline::GeneralIO.reset
1011
send(:core).config.instance_variable_set(:@test_mode, true)
1112
send(:core).config.reset
1213
end
@@ -17,6 +18,14 @@ def test_reset
1718
end
1819
end
1920

21+
def start_pasting
22+
Reline::GeneralIO.start_pasting
23+
end
24+
25+
def finish_pasting
26+
Reline::GeneralIO.finish_pasting
27+
end
28+
2029
RELINE_TEST_ENCODING ||=
2130
if ENV['RELINE_TEST_ENCODING']
2231
Encoding.find(ENV['RELINE_TEST_ENCODING'])

test/reline/test_key_actor_vi.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,4 +1353,26 @@ def test_vi_next_char_with_operator
13531353
assert_cursor(0)
13541354
assert_cursor_max(3)
13551355
end
1356+
1357+
def test_pasting
1358+
start_pasting
1359+
input_keys('ab')
1360+
finish_pasting
1361+
input_keys('c')
1362+
assert_line('abc')
1363+
assert_byte_pointer_size('abc')
1364+
assert_cursor(3)
1365+
assert_cursor_max(3)
1366+
end
1367+
1368+
def test_pasting_fullwidth
1369+
start_pasting
1370+
input_keys('あ')
1371+
finish_pasting
1372+
input_keys('い')
1373+
assert_line('あい')
1374+
assert_byte_pointer_size('あい')
1375+
assert_cursor(4)
1376+
assert_cursor_max(4)
1377+
end
13561378
end

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ def test_autowrap
6262
EOC
6363
end
6464

65+
def test_fullwidth
66+
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
67+
write(":あ\n")
68+
close
69+
assert_screen(<<~EOC)
70+
Multiline REPL.
71+
prompt> :あ
72+
=> :あ
73+
prompt>
74+
EOC
75+
end
76+
77+
def test_two_fullwidth
78+
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
79+
write(":あい\n")
80+
close
81+
assert_screen(<<~EOC)
82+
Multiline REPL.
83+
prompt> :あい
84+
=> :あい
85+
prompt>
86+
EOC
87+
end
88+
6589
def test_finish_autowrapped_line
6690
start_terminal(10, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
6791
write("[{'user'=>{'email'=>'a@a', 'id'=>'ABC'}, 'version'=>4, 'status'=>'succeeded'}]\n")

0 commit comments

Comments
 (0)