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

ruby-changes:63924

From: aycabta <ko1@a...>
Date: Sat, 5 Dec 2020 03:09:15 +0900 (JST)
Subject: [ruby-changes:63924] 6be3b2da19 (master): [ruby/reline] Implement vi_yank

https://git.ruby-lang.org/ruby.git/commit/?id=6be3b2da19

From 6be3b2da19a45e21c63ed0a9c51fa4e1a0d1bd08 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Mon, 2 Nov 2020 21:57:54 +0900
Subject: [ruby/reline] Implement vi_yank

https://github.com/ruby/reline/commit/164aaf9a5f

diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 86d57d9..8425a47 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -2083,6 +2083,14 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L2083
   end
 
   private def vi_yank(key)
+    @waiting_operator_proc = proc { |cursor_diff, byte_pointer_diff|
+      if byte_pointer_diff > 0
+        cut = @line.byteslice(@byte_pointer, byte_pointer_diff)
+      elsif byte_pointer_diff < 0
+        cut = @line.byteslice(@byte_pointer + byte_pointer_diff, -byte_pointer_diff)
+      end
+      copy_for_vi(cut)
+    }
   end
 
   private def vi_list_or_eof(key)
diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb
index a244927..6f318db 100644
--- a/test/reline/test_key_actor_vi.rb
+++ b/test/reline/test_key_actor_vi.rb
@@ -1276,4 +1276,22 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_key_actor_vi.rb#L1276
     assert_cursor_max(3)
     assert_line('abc')
   end
+
+  def test_vi_yank
+    input_keys("foo bar\C-[0")
+    assert_line('foo bar')
+    assert_byte_pointer_size('')
+    assert_cursor(0)
+    assert_cursor_max(7)
+    input_keys('y3l')
+    assert_line('foo bar')
+    assert_byte_pointer_size('')
+    assert_cursor(0)
+    assert_cursor_max(7)
+    input_keys('P')
+    assert_line('foofoo bar')
+    assert_byte_pointer_size('fo')
+    assert_cursor(2)
+    assert_cursor_max(10)
+  end
 end
-- 
cgit v0.10.2


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

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