[前][次][番号順一覧][スレッド一覧]

ruby-changes:64568

From: aycabta <ko1@a...>
Date: Thu, 24 Dec 2020 23:32:39 +0900 (JST)
Subject: [ruby-changes:64568] 9a7647d9eb (master): [ruby/reline] Doesn't contain terminate spaces by cw

https://git.ruby-lang.org/ruby.git/commit/?id=9a7647d9eb

From 9a7647d9eb59c8ed00b0de46fbf26f744a4158c5 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Thu, 24 Dec 2020 22:53:24 +0900
Subject: [ruby/reline] Doesn't contain terminate spaces by cw

This closes ruby/reline#233.

https://github.com/ruby/reline/commit/4c3f2e2eae

diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index c1564fa..d4075c0 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -219,6 +219,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L219
     @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 https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L2189
 
   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 https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L2317
   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 https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L2329
       @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 b7cecfe..9b5ddc4 100644
--- a/lib/reline/unicode.rb
+++ b/lib/reline/unicode.rb
@@ -458,7 +458,7 @@ class Reline::Unicode https://github.com/ruby/ruby/blob/trunk/lib/reline/unicode.rb#L458
     [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 https://github.com/ruby/ruby/blob/trunk/lib/reline/unicode.rb#L488
       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)
diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb
index 21f4e89..6ac776f 100644
--- a/test/reline/test_key_actor_vi.rb
+++ b/test/reline/test_key_actor_vi.rb
@@ -1288,21 +1288,39 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_key_actor_vi.rb#L1288
     assert_cursor(8)
     assert_cursor_max(19)
     assert_line('aaa bbb ccc ddd eee')
-    input_keys('cwaiueo ')
-    assert_byte_pointer_size('aaa bbb aiueo ')
-    assert_cursor(14)
+    input_keys('cwaiueo')
+    assert_byte_pointer_size('aaa bbb aiueo')
+    assert_cursor(13)
     assert_cursor_max(21)
     assert_line('aaa bbb aiueo ddd eee')
     input_keys("\C-[")
-    assert_byte_pointer_size('aaa bbb aiueo')
-    assert_cursor(13)
+    assert_byte_pointer_size('aaa bbb aiue')
+    assert_cursor(12)
     assert_cursor_max(21)
     assert_line('aaa bbb aiueo ddd eee')
     input_keys('cb')
     assert_byte_pointer_size('aaa bbb ')
     assert_cursor(8)
-    assert_cursor_max(16)
-    assert_line('aaa bbb  ddd eee')
+    assert_cursor_max(17)
+    assert_line('aaa bbb o ddd eee')
+  end
+
+  def test_vi_change_meta_with_vi_next_word
+    input_keys("foo  bar  baz\C-[0w")
+    assert_byte_pointer_size('foo  ')
+    assert_cursor(5)
+    assert_cursor_max(13)
+    assert_line('foo  bar  baz')
+    input_keys('cwhoge')
+    assert_byte_pointer_size('foo  hoge')
+    assert_cursor(9)
+    assert_cursor_max(14)
+    assert_line('foo  hoge  baz')
+    input_keys("\C-[")
+    assert_byte_pointer_size('foo  hog')
+    assert_cursor(8)
+    assert_cursor_max(14)
+    assert_line('foo  hoge  baz')
   end
 
   def test_unimplemented_vi_command_should_be_no_op
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]