Backspace and delete now work in console

This commit is contained in:
Kovid Goyal 2010-09-21 22:28:49 -06:00
parent e7adf45c01
commit a41f481ee7

View File

@ -143,6 +143,8 @@ class Console(QTextEdit):
Qt.Key_End : self.end_pressed, Qt.Key_End : self.end_pressed,
Qt.Key_Left : self.left_pressed, Qt.Key_Left : self.left_pressed,
Qt.Key_Right : self.right_pressed, Qt.Key_Right : self.right_pressed,
Qt.Key_Backspace : self.backspace_pressed,
Qt.Key_Delete : self.delete_pressed,
} # }}} } # }}}
motd = textwrap.dedent('''\ motd = textwrap.dedent('''\
@ -327,6 +329,22 @@ class Console(QTextEdit):
self.setTextCursor(c) self.setTextCursor(c)
self.ensureCursorVisible() 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): def right_pressed(self):
lineno, pos = self.cursor_pos lineno, pos = self.cursor_pos
if lineno < 0: return if lineno < 0: return