diff --git a/cola/widgets/grep.py b/cola/widgets/grep.py index 254d7f90a..8210fd728 100644 --- a/cola/widgets/grep.py +++ b/cola/widgets/grep.py @@ -107,6 +107,8 @@ def __init__(self, parent): self.connect(self.input_txt, SIGNAL('textChanged(QString)'), self.input_txt_changed) + self.connect(self.result_txt, SIGNAL('leave()'), + lambda: self.input_txt.setFocus()) qtutils.add_action(self.input_txt, 'FocusResults', lambda: self.result_txt.setFocus(), @@ -231,6 +233,18 @@ def paintEvent(self, event): painter = QtGui.QPainter(self.viewport()) painter.fillRect(rect, Qt.SolidPattern) + def keyPressEvent(self, event): + if event.key() == Qt.Key_Up: + cursor = self.textCursor() + position = cursor.position() + if position == 0 and not cursor.hasSelection(): + # The cursor is at the beginning of the line. + # If we have selection then simply reset the cursor. + # Otherwise, emit a signal so that the parent can + # change focus. + self.emit(SIGNAL('leave()')) + return HintedTextView.keyPressEvent(self, event) + def goto_grep(line): """Called when Search -> Grep's right-click 'goto' action."""