summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-11-15 16:50:11 +0900
committeraycabta <aycabta@gmail.com>2019-11-15 16:50:40 +0900
commitfa7618e4c1b382cb5863161017ef89116af3e24f (patch)
tree5aa327533c1cd5a6b78152ba09c92cc1d6416dac /lib
parent6744593b8cd836967b40a4d76a9ac301b9e0f973 (diff)
Implement em_set_mark and em_exchange_mark
Diffstat (limited to 'lib')
-rw-r--r--lib/reline/ansi.rb4
-rw-r--r--lib/reline/line_editor.rb17
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb
index b0f4d3dbff..12ae903186 100644
--- a/lib/reline/ansi.rb
+++ b/lib/reline/ansi.rb
@@ -6,7 +6,9 @@ class Reline::ANSI
[27, 91, 68] => :ed_prev_char, # ←
[27, 91, 51, 126] => :key_delete, # Del
[27, 91, 49, 126] => :ed_move_to_beg, # Home
- [27, 91, 52, 126] => :ed_move_to_end, # End
+ [27, 91, 68] => :ed_prev_char, # ←
+ [27, 32] => :em_set_mark, # M-<space>
+ [24, 24] => :em_exchange_mark, # C-x C-x TODO also add Windows
}
@@input = STDIN
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index ddb9e0ae2a..8071080ccf 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -138,6 +138,7 @@ class Reline::LineEditor
def reset_variables(prompt = '', encoding = Encoding.default_external)
@prompt = prompt
+ @mark_pointer = nil
@encoding = encoding
@is_multiline = false
@finished = false
@@ -1941,4 +1942,20 @@ class Reline::LineEditor
arg -= 1
vi_join_lines(key, arg: arg) if arg > 0
end
+
+ private def em_set_mark(key)
+ @mark_pointer = [@byte_pointer, @line_index]
+ end
+ alias_method :set_mark, :em_set_mark
+
+ private def em_exchange_mark(key)
+ new_pointer = [@byte_pointer, @line_index]
+ @previous_line_index = @line_index
+ @byte_pointer, @line_index = @mark_pointer
+ @byte_pointer, @line_index = @mark_pointer
+ @cursor = calculate_width(@line.byteslice(0, @byte_pointer))
+ @cursor_max = calculate_width(@line)
+ @mark_pointer = new_pointer
+ end
+ alias_method :exchange_point_and_mark, :em_exchange_mark
end