From 0497a8f7a90135a10441798986a769e8403a3646 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Thu, 13 Jan 2022 13:25:00 +1000 Subject: [PATCH] editor: Add the abort command - For now it only unsets the current selection. --- diff_edit/editor.py | 5 ++++- tests/editor_test.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/diff_edit/editor.py b/diff_edit/editor.py index fc84f36..4f83097 100755 --- a/diff_edit/editor.py +++ b/diff_edit/editor.py @@ -540,6 +540,9 @@ class Editor: def undo(self): self.text_widget[:], self._cursor_x, self._cursor_y = self.history.pop() + def abort_command(self): + self.mark = None + def get_text(self): return self.text_widget.get_text() @@ -644,7 +647,7 @@ class Editor: terminal.CTRL_L: center_cursor, terminal.ALT_SEMICOLON: comment_lines, terminal.ALT_c: cycle_syntax_highlighting, terminal.CTRL_X: prefix, terminal.ESC: quit, terminal.CTRL_C: ctrl_c, terminal.CTRL_K: delete_line, terminal.TAB: tab_align, - terminal.CTRL_UNDERSCORE: undo} + terminal.CTRL_UNDERSCORE: undo, terminal.CTRL_G: abort_command} def main(): diff --git a/tests/editor_test.py b/tests/editor_test.py index 79d5d8f..9bcec3d 100755 --- a/tests/editor_test.py +++ b/tests/editor_test.py @@ -224,6 +224,12 @@ class EditorTestCase(unittest.TestCase): self._assert_change(self.editor.undo, "a\nb", (0, 1)) self._assert_change(self.editor.undo, "ab", (1, 0)) + def test_abort_command(self): + self._set_editor("", (0, 0)) + self.editor.set_mark() + self.editor.abort_command() + self.assertEqual(self.editor.mark, None) + if __name__ == "__main__": unittest.main()