diff --git a/TODO b/TODO index 4c5b1fc..a5aedf6 100644 --- a/TODO +++ b/TODO @@ -5,7 +5,6 @@ Todo: - Bulk indent/dedent. - Search. - Search and replace. -- Overwrite mode. - Large pastes. @@ -31,6 +30,7 @@ Done: - Put it on github. - tab key should align code. - Right align the left editor. +- Overwrite mode. Shelved: diff --git a/diff_edit/editor.py b/diff_edit/editor.py index c1a393f..86c0ac5 100755 --- a/diff_edit/editor.py +++ b/diff_edit/editor.py @@ -194,6 +194,7 @@ class Editor: self.last_height = 40 self.is_editing = True self.theme_index = 0 + self.is_overwriting = False self.previous_term_code = None self.history = [] @@ -341,8 +342,9 @@ class Editor: def insert_text(self, text): try: current_line = self.text_widget[self.cursor_y] - new_line = current_line[:self.cursor_x] + text + current_line[self.cursor_x:] - self.text_widget[self.cursor_y] = new_line + replace_count = len(text) if self.is_overwriting else 0 + self.text_widget[self.cursor_y] = (current_line[:self.cursor_x] + text + + current_line[self.cursor_x+replace_count:]) except IndexError: self.text_widget.append(text) self.cursor_x += len(text) @@ -533,6 +535,9 @@ class Editor: def undo(self): self.text_widget[:], self._cursor_x, self._cursor_y = self.history.pop() + def toggle_overwrite(self): + self.is_overwriting = not self.is_overwriting + def abort_command(self): self.mark = None self.ring_bell() @@ -644,7 +649,8 @@ 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_Z: undo, terminal.CTRL_G: abort_command} + terminal.CTRL_UNDERSCORE: undo, terminal.CTRL_Z: undo, terminal.CTRL_G: abort_command, + terminal.INSERT: toggle_overwrite} def main(): diff --git a/setup.py b/setup.py index de06887..33f931f 100755 --- a/setup.py +++ b/setup.py @@ -18,4 +18,4 @@ setup(name="diff-edit", entry_points={"console_scripts": ["diff-edit=diff_edit:main"]}, install_requires=[ "pygments==2.10.0", "docopt==0.6.2", - "fill3 @ git+https://github.com/ahamilton/eris@v2022.01.27#subdirectory=fill3"]) + "fill3 @ git+https://github.com/ahamilton/eris@v2022.01.28#subdirectory=fill3"]) diff --git a/tests/editor_test.py b/tests/editor_test.py index b61ca8f..a0ffccb 100755 --- a/tests/editor_test.py +++ b/tests/editor_test.py @@ -80,6 +80,15 @@ class EditorTestCase(unittest.TestCase): self._assert_editor("a", (1, 0)) self.editor.insert_text("bc") self._assert_editor("abc", (3, 0)) + # overwrite + self.editor.toggle_overwrite() + self.editor.cursor_left() + self.editor.insert_text("d") + self._assert_editor("abd", (3, 0)) + self.editor.cursor_left() + self.editor.cursor_left() + self.editor.insert_text("ef") + self._assert_editor("aef", (3, 0)) def test_enter(self): self._set_editor("ab", (1, 0))