summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-12-24 22:53:24 +0900
committeraycabta <aycabta@gmail.com>2020-12-24 23:26:22 +0900
commit9a7647d9eb59c8ed00b0de46fbf26f744a4158c5 (patch)
tree9a0c79feb8691449eeabe8ed96611ff3fbb82d4c /lib
parent78421319d0401c37497f2b5df7110e92eef9f0e4 (diff)
[ruby/reline] Doesn't contain terminate spaces by cw
This closes ruby/reline#233. https://github.com/ruby/reline/commit/4c3f2e2eae
Diffstat (limited to 'lib')
-rw-r--r--lib/reline/line_editor.rb5
-rw-r--r--lib/reline/unicode.rb3
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index c1564fa57e..d4075c0934 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -219,6 +219,7 @@ class Reline::LineEditor
@continuous_insertion_buffer = String.new(encoding: @encoding)
@scroll_partial_screen = nil
@prev_mode_icon = nil
+ @drop_terminate_spaces = false
reset_line
end
@@ -2188,7 +2189,7 @@ class Reline::LineEditor
private def vi_next_word(key, arg: 1)
if @line.bytesize > @byte_pointer
- byte_size, width = Reline::Unicode.vi_forward_word(@line, @byte_pointer)
+ byte_size, width = Reline::Unicode.vi_forward_word(@line, @byte_pointer, @drop_terminate_spaces)
@byte_pointer += byte_size
@cursor += width
end
@@ -2316,6 +2317,7 @@ class Reline::LineEditor
end
private def vi_change_meta(key, arg: 1)
+ @drop_terminate_spaces = true
@waiting_operator_proc = proc { |cursor_diff, byte_pointer_diff|
if byte_pointer_diff > 0
@line, cut = byteslice!(@line, @byte_pointer, byte_pointer_diff)
@@ -2327,6 +2329,7 @@ class Reline::LineEditor
@cursor_max -= cursor_diff.abs
@byte_pointer += byte_pointer_diff if byte_pointer_diff < 0
@config.editing_mode = :vi_insert
+ @drop_terminate_spaces = false
}
@waiting_operator_vi_arg = arg
end
diff --git a/lib/reline/unicode.rb b/lib/reline/unicode.rb
index b7cecfeaee..9b5ddc4622 100644
--- a/lib/reline/unicode.rb
+++ b/lib/reline/unicode.rb
@@ -458,7 +458,7 @@ class Reline::Unicode
[byte_size, width]
end
- def self.vi_forward_word(line, byte_pointer)
+ def self.vi_forward_word(line, byte_pointer, drop_terminate_spaces = false)
if line.bytesize > byte_pointer
size = get_next_mbchar_size(line, byte_pointer)
mbchar = line.byteslice(byte_pointer, size)
@@ -488,6 +488,7 @@ class Reline::Unicode
width += get_mbchar_width(mbchar)
byte_size += size
end
+ return [byte_size, width] if drop_terminate_spaces
while line.bytesize > (byte_pointer + byte_size)
size = get_next_mbchar_size(line, byte_pointer + byte_size)
mbchar = line.byteslice(byte_pointer + byte_size, size)