summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Slenders <jonathan@slenders.be>2016-07-23 15:53:18 +0200
committerJonathan Slenders <jonathan@slenders.be>2016-07-23 15:53:25 +0200
commite2170df91a4edf92ff170c29430e3fe884a9e326 (patch)
tree4636a2174f1c020fff19875f649c6470a7ce0e15
parentde598e99483aae4bbdd5a5b6a2b3d485f4985bba (diff)
Bug fix in ControlX-ControlX binding + unit test.
The cursor did not go to the start of the line when we were at the latest line of a multi-line input, or in a single line input.
-rw-r--r--prompt_toolkit/key_binding/bindings/emacs.py2
-rw-r--r--tests/test_cli.py15
2 files changed, 16 insertions, 1 deletions
diff --git a/prompt_toolkit/key_binding/bindings/emacs.py b/prompt_toolkit/key_binding/bindings/emacs.py
index 79949799..f173b4e2 100644
--- a/prompt_toolkit/key_binding/bindings/emacs.py
+++ b/prompt_toolkit/key_binding/bindings/emacs.py
@@ -198,7 +198,7 @@ def load_emacs_bindings(registry, filter=Always()):
"""
buffer = event.current_buffer
- if buffer.document.current_char == '\n':
+ if buffer.document.is_cursor_at_the_end_of_line:
buffer.cursor_position += buffer.document.get_start_of_line_position(after_whitespace=False)
else:
buffer.cursor_position += buffer.document.get_end_of_line_position()
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 81acef6e..29725aab 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -245,6 +245,21 @@ def test_emacs_other_bindings():
assert result.text == 'hello X'
+def test_controlx_controlx():
+ # At the end: go to the start of the line.
+ result, cli = _feed_cli_with_input('hello world\x18\x18X\n')
+ assert result.text == 'Xhello world'
+ assert result.cursor_position == 1
+
+ # At the start: go to the end of the line.
+ result, cli = _feed_cli_with_input('hello world\x01\x18\x18X\n')
+ assert result.text == 'hello worldX'
+
+ # Left, Left Control-X Control-X: go to the end of the line.
+ result, cli = _feed_cli_with_input('hello world\x1b[D\x1b[D\x18\x18X\n')
+ assert result.text == 'hello worldX'
+
+
def test_emacs_history_bindings():
# Adding a new item to the history.
history = _history()