From fc1e292125256c6b2f9e11e6ef1aac4be9702922 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 31 Dec 2011 20:28:20 -0800 Subject: [PATCH] widgets.commitmsg: Refine the keyboard navigation Allow shift+up/down in the description field to select text when on the first and last lines, respectively. Signed-off-by: David Aguilar --- cola/widgets/commitmsg.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cola/widgets/commitmsg.py b/cola/widgets/commitmsg.py index 7cad041b..c9a3b483 100644 --- a/cola/widgets/commitmsg.py +++ b/cola/widgets/commitmsg.py @@ -378,13 +378,21 @@ class CommitMessageTextEdit(HintedTextEdit): cursor = self.textCursor() position = cursor.position() if position == 0: - self.emit_shift_tab() + if cursor.hasSelection(): + cursor.setPosition(0) + self.setTextCursor(cursor) + else: + self.emit_shift_tab() event.ignore() return text_before = unicode(self.toPlainText())[:position] lines_before = text_before.count('\n') if lines_before == 0: - cursor.setPosition(0) + if event.modifiers() & Qt.ShiftModifier: + mode = QtGui.QTextCursor.KeepAnchor + else: + mode = QtGui.QTextCursor.MoveAnchor + cursor.setPosition(0, mode) self.setTextCursor(cursor) event.ignore() return @@ -395,7 +403,11 @@ class CommitMessageTextEdit(HintedTextEdit): text_after = all_text[position:] lines_after = text_after.count('\n') if lines_after == 0: - cursor.setPosition(len(all_text)) + if event.modifiers() & Qt.ShiftModifier: + mode = QtGui.QTextCursor.KeepAnchor + else: + mode = QtGui.QTextCursor.MoveAnchor + cursor.setPosition(len(all_text), mode) self.setTextCursor(cursor) event.ignore() return -- 2.11.4.GIT