From a1e978597420c16b54e80c72db1fadaa6422182a Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Wed, 28 Dec 2011 20:15:57 -0800 Subject: [PATCH] widgets.commitmsg: Make Up/Down arrows more useful Pressing 'Up' while on the first line and 'Down' while on the last line should move the cursor to the beginning/end of the line. The summary works this way so the description editor should too. Signed-off-by: David Aguilar --- cola/widgets/commitmsg.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cola/widgets/commitmsg.py b/cola/widgets/commitmsg.py index c7a796fb..6646e310 100644 --- a/cola/widgets/commitmsg.py +++ b/cola/widgets/commitmsg.py @@ -1,5 +1,6 @@ from PyQt4 import QtGui from PyQt4 import QtCore +from PyQt4.QtCore import Qt from PyQt4.QtCore import SIGNAL import cola @@ -454,5 +455,29 @@ class CommitMessageTextEdit(QtGui.QTextEdit): return False + def keyPressEvent(self, event): + if event.key() == Qt.Key_Up: + cursor = self.textCursor() + position = cursor.position() + text_before = unicode(self.toPlainText())[:position] + lines_before = text_before.count('\n') + if lines_before == 0: + cursor.setPosition(0) + self.setTextCursor(cursor) + event.ignore() + return + elif event.key() == Qt.Key_Down: + cursor = self.textCursor() + position = cursor.position() + all_text = unicode(self.toPlainText()) + text_after = all_text[position:] + lines_after = text_after.count('\n') + if lines_after == 0: + cursor.setPosition(len(all_text)) + self.setTextCursor(cursor) + event.ignore() + return + super(CommitMessageTextEdit, self).keyPressEvent(event) + def shift_tab(self): self.emit(SIGNAL('shiftTab()')) -- 2.11.4.GIT