[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:
aycabta 2020-11-08 21:56:27 +09:00
Родитель ba8e5f77eb
Коммит 9750c27afc
5 изменённых файлов: 72 добавлений и 1 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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'])

Просмотреть файл

@ -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

Просмотреть файл

@ -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")