mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/reline] Call process_insert when the end of pasting plural fullwidth chars
https://github.com/ruby/reline/commit/594484d9f9
This commit is contained in:
parent
ba8e5f77eb
commit
9750c27afc
5 changed files with 72 additions and 1 deletions
|
@ -1,6 +1,10 @@
|
||||||
require 'timeout'
|
require 'timeout'
|
||||||
|
|
||||||
class Reline::GeneralIO
|
class Reline::GeneralIO
|
||||||
|
def self.reset
|
||||||
|
@@pasting = false
|
||||||
|
end
|
||||||
|
|
||||||
def self.encoding
|
def self.encoding
|
||||||
RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
|
RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
|
||||||
end
|
end
|
||||||
|
@ -67,8 +71,18 @@ class Reline::GeneralIO
|
||||||
def self.set_winch_handler(&handler)
|
def self.set_winch_handler(&handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@pasting = false
|
||||||
|
|
||||||
def self.in_pasting?
|
def self.in_pasting?
|
||||||
false
|
@@pasting
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.start_pasting
|
||||||
|
@@pasting = true
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.finish_pasting
|
||||||
|
@@pasting = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.prep
|
def self.prep
|
||||||
|
|
|
@ -1161,6 +1161,8 @@ class Reline::LineEditor
|
||||||
if Reline::IOGate.in_pasting?
|
if Reline::IOGate.in_pasting?
|
||||||
@continuous_insertion_buffer << str
|
@continuous_insertion_buffer << str
|
||||||
return
|
return
|
||||||
|
elsif not @continuous_insertion_buffer.empty?
|
||||||
|
process_insert
|
||||||
end
|
end
|
||||||
width = Reline::Unicode.get_mbchar_width(str)
|
width = Reline::Unicode.get_mbchar_width(str)
|
||||||
if @cursor == @cursor_max
|
if @cursor == @cursor_max
|
||||||
|
|
|
@ -7,6 +7,7 @@ module Reline
|
||||||
def test_mode
|
def test_mode
|
||||||
remove_const('IOGate') if const_defined?('IOGate')
|
remove_const('IOGate') if const_defined?('IOGate')
|
||||||
const_set('IOGate', Reline::GeneralIO)
|
const_set('IOGate', Reline::GeneralIO)
|
||||||
|
Reline::GeneralIO.reset
|
||||||
send(:core).config.instance_variable_set(:@test_mode, true)
|
send(:core).config.instance_variable_set(:@test_mode, true)
|
||||||
send(:core).config.reset
|
send(:core).config.reset
|
||||||
end
|
end
|
||||||
|
@ -17,6 +18,14 @@ module Reline
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def start_pasting
|
||||||
|
Reline::GeneralIO.start_pasting
|
||||||
|
end
|
||||||
|
|
||||||
|
def finish_pasting
|
||||||
|
Reline::GeneralIO.finish_pasting
|
||||||
|
end
|
||||||
|
|
||||||
RELINE_TEST_ENCODING ||=
|
RELINE_TEST_ENCODING ||=
|
||||||
if ENV['RELINE_TEST_ENCODING']
|
if ENV['RELINE_TEST_ENCODING']
|
||||||
Encoding.find(ENV['RELINE_TEST_ENCODING'])
|
Encoding.find(ENV['RELINE_TEST_ENCODING'])
|
||||||
|
|
|
@ -1353,4 +1353,26 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase
|
||||||
assert_cursor(0)
|
assert_cursor(0)
|
||||||
assert_cursor_max(3)
|
assert_cursor_max(3)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -62,6 +62,30 @@ begin
|
||||||
EOC
|
EOC
|
||||||
end
|
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
|
def test_finish_autowrapped_line
|
||||||
start_terminal(10, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}, startup_message: 'Multiline REPL.')
|
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")
|
write("[{'user'=>{'email'=>'a@a', 'id'=>'ABC'}, 'version'=>4, 'status'=>'succeeded'}]\n")
|
||||||
|
|
Loading…
Add table
Reference in a new issue