From a41f481ee7d3a72b727c1f6b2d98ae10443cb0d2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 21 Sep 2010 22:28:49 -0600 Subject: [PATCH] Backspace and delete now work in console --- src/calibre/utils/pyconsole/console.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/calibre/utils/pyconsole/console.py b/src/calibre/utils/pyconsole/console.py index 164cf4e2ca..aa0ff84d77 100644 --- a/src/calibre/utils/pyconsole/console.py +++ b/src/calibre/utils/pyconsole/console.py @@ -143,6 +143,8 @@ class Console(QTextEdit): Qt.Key_End : self.end_pressed, Qt.Key_Left : self.left_pressed, Qt.Key_Right : self.right_pressed, + Qt.Key_Backspace : self.backspace_pressed, + Qt.Key_Delete : self.delete_pressed, } # }}} motd = textwrap.dedent('''\ @@ -327,6 +329,22 @@ class Console(QTextEdit): self.setTextCursor(c) self.ensureCursorVisible() + def backspace_pressed(self): + lineno, pos = self.cursor_pos + if lineno < 0: return + if pos > self.prompt_len: + self.cursor.deletePreviousChar() + elif lineno > 0: + c = self.cursor + c.movePosition(c.Up) + c.movePosition(c.EndOfLine) + self.setTextCursor(c) + self.ensureCursorVisible() + + def delete_pressed(self): + self.cursor.deleteChar() + self.ensureCursorVisible() + def right_pressed(self): lineno, pos = self.cursor_pos if lineno < 0: return