Skip to content

Commit

Permalink
grep: allow moving between query and result using the arrow keys
Browse files Browse the repository at this point in the history
The query input field already knew to focus the results when pressing
either enter, return, or the down-arrow key.  Teach the results field to
focus the input field when the up-arrow is pressed.

This makes the behavior consistent with the commit message editor.

Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Mar 30, 2013
1 parent 1e52aa0 commit 0036465
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cola/widgets/grep.py
Expand Up @@ -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(),
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 0036465

Please sign in to comment.