Skip to content

Commit abb56e5

Browse files
committed
Skip em_exchange_mark without mark
1 parent 710ca23 commit abb56e5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/reline/line_editor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,7 @@ def finish
23422342
alias_method :set_mark, :em_set_mark
23432343

23442344
private def em_exchange_mark(key)
2345+
return unless @mark_pointer
23452346
new_pointer = [@byte_pointer, @line_index]
23462347
@previous_line_index = @line_index
23472348
@byte_pointer, @line_index = @mark_pointer

test/reline/test_key_actor_emacs.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,26 @@ def test_em_set_mark_and_em_exchange_mark
19261926
assert_equal([0, 0], @line_editor.instance_variable_get(:@mark_pointer))
19271927
end
19281928

1929+
def test_em_exchange_mark_without_mark
1930+
input_keys('aaa bbb ccc ddd')
1931+
assert_byte_pointer_size('aaa bbb ccc ddd')
1932+
assert_cursor(15)
1933+
assert_cursor_max(15)
1934+
assert_line('aaa bbb ccc ddd')
1935+
input_keys("\C-a\M-f", false)
1936+
assert_byte_pointer_size('aaa')
1937+
assert_cursor(3)
1938+
assert_cursor_max(15)
1939+
assert_line('aaa bbb ccc ddd')
1940+
assert_equal(nil, @line_editor.instance_variable_get(:@mark_pointer))
1941+
input_key_by_symbol(:em_exchange_mark)
1942+
assert_byte_pointer_size('aaa')
1943+
assert_cursor(3)
1944+
assert_cursor_max(15)
1945+
assert_line('aaa bbb ccc ddd')
1946+
assert_equal(nil, @line_editor.instance_variable_get(:@mark_pointer))
1947+
end
1948+
19291949
def test_modify_lines_with_wrong_rs
19301950
verbose, $VERBOSE = $VERBOSE, nil
19311951
original_global_slash = $/

0 commit comments

Comments
 (0)