From 716ba4a12732d94a50fb31bcaca4ce07bc4b6870 Mon Sep 17 00:00:00 2001 From: aycabta Date: Mon, 27 May 2019 05:45:08 +0900 Subject: [PATCH] Implement J to join lines in vi command mode --- lib/reline/key_actor/vi_command.rb | 2 +- lib/reline/line_editor.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/reline/key_actor/vi_command.rb b/lib/reline/key_actor/vi_command.rb index ac8458c87c..130fcb04a6 100644 --- a/lib/reline/key_actor/vi_command.rb +++ b/lib/reline/key_actor/vi_command.rb @@ -149,7 +149,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base # 73 I :vi_insert_at_bol, # 74 J - :ed_search_next_history, + :vi_join_lines, # 75 K :ed_search_prev_history, # 76 L diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index f4e012688e..83c0d419c3 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -40,6 +40,7 @@ class Reline::LineEditor vi_paste_prev vi_paste_next vi_replace_char + vi_join_lines } VI_OPERATORS = %i{ @@ -1632,4 +1633,18 @@ class Reline::LineEditor end @waiting_proc = nil end + + private def vi_join_lines(key, arg: 1) + if @is_multiline and @buffer_of_lines.size > @line_index + 1 + @cursor = calculate_width(@line) + @byte_pointer = @line.bytesize + @line += ' ' + @buffer_of_lines.delete_at(@line_index + 1).gsub(/\A +/, '') + @cursor_max = calculate_width(@line) + @buffer_of_lines[@line_index] = @line + @rerender_all = true + @rest_height += 1 + end + arg -= 1 + vi_join_lines(key, arg: arg) if arg > 0 + end end