diff --git a/diff_edit/editor.py b/diff_edit/editor.py index 780b300..ddd8b91 100755 --- a/diff_edit/editor.py +++ b/diff_edit/editor.py @@ -425,6 +425,14 @@ class Editor: self.previous_word() self.delete_selection() + def delete_line(self): + empty_selection = self.text_widget[self.cursor_y][self.cursor_x:].strip() == "" + self.set_mark() + self.jump_to_end_of_line() + self.delete_selection() + if empty_selection: + self.delete_character() + def join_lines(self): if self.cursor_y == 0: self.jump_to_start_of_line() @@ -564,7 +572,7 @@ class Editor: terminal.ALT_H: highlight_block, terminal.CTRL_R: syntax_highlight_all, terminal.CTRL_L: center_cursor, terminal.ALT_SEMICOLON: comment_highlighted, terminal.ALT_c: cycle_syntax_highlighting, terminal.CTRL_X: prefix, terminal.ESC: quit, - terminal.CTRL_C: ctrl_c} + terminal.CTRL_C: ctrl_c, terminal.CTRL_K: delete_line} def main(): diff --git a/tests/editor_test.py b/tests/editor_test.py index 533cec9..c68b7c4 100755 --- a/tests/editor_test.py +++ b/tests/editor_test.py @@ -150,6 +150,17 @@ class EditorTestCase(unittest.TestCase): (self.editor.join_lines, "ab- -cd ", (0, 0)), (self.editor.join_lines, "ab- -cd ", (0, 0))]) + def test_delete_line(self): + text = "a \ndef" + self._set_editor(text, (1, 0)) + self._assert_changes([(self.editor.delete_line, "adef", (1, 0)), + (self.editor.delete_line, "a", (1, 0))]) + text = "\nabc" + self._set_editor(text, (0, 0)) + self._assert_changes([(self.editor.delete_line, "abc", (0, 0)), + (self.editor.delete_line, "", (0, 0)), + (self.editor.delete_line, "", (0, 0))]) + if __name__ == "__main__": unittest.main()