Merge pull request #204 from glutanimate/tagedit-improve-keyboard-nav
Improve keyboard navigation in TagEdit
This commit is contained in:
commit
598df47967
@ -36,7 +36,28 @@ class TagEdit(QLineEdit):
|
||||
self.showCompleter()
|
||||
|
||||
def keyPressEvent(self, evt):
|
||||
if evt.key() in (Qt.Key_Up, Qt.Key_Down):
|
||||
# show completer on arrow key up/down
|
||||
if not self.completer.popup().isVisible():
|
||||
self.showCompleter()
|
||||
return
|
||||
if (evt.key() == Qt.Key_Tab and evt.modifiers() & Qt.ControlModifier):
|
||||
# select next completion
|
||||
if not self.completer.popup().isVisible():
|
||||
self.showCompleter()
|
||||
index = self.completer.currentIndex()
|
||||
self.completer.popup().setCurrentIndex(index)
|
||||
cur_row = index.row()
|
||||
if not self.completer.setCurrentRow(cur_row + 1):
|
||||
self.completer.setCurrentRow(0)
|
||||
return
|
||||
if evt.key() in (Qt.Key_Enter, Qt.Key_Return):
|
||||
# apply first completion if no suggestion selected
|
||||
selected_row = self.completer.popup().currentIndex().row()
|
||||
if selected_row == -1:
|
||||
self.completer.setCurrentRow(0)
|
||||
index = self.completer.currentIndex()
|
||||
self.completer.popup().setCurrentIndex(index)
|
||||
self.hideCompleter()
|
||||
QWidget.keyPressEvent(self, evt)
|
||||
return
|
||||
@ -70,12 +91,15 @@ class TagCompleter(QCompleter):
|
||||
self.cursor = None
|
||||
|
||||
def splitPath(self, tags):
|
||||
tags = tags.strip()
|
||||
tags = re.sub(" +", " ", tags)
|
||||
self.tags = self.edit.col.tags.split(tags)
|
||||
stripped_tags = tags.strip()
|
||||
stripped_tags = re.sub(" +", " ", stripped_tags)
|
||||
self.tags = self.edit.col.tags.split(stripped_tags)
|
||||
self.tags.append("")
|
||||
p = self.edit.cursorPosition()
|
||||
self.cursor = tags.count(" ", 0, p)
|
||||
if tags.endswith(" "):
|
||||
self.cursor = len(self.tags) - 1
|
||||
else:
|
||||
self.cursor = stripped_tags.count(" ", 0, p)
|
||||
return [self.tags[self.cursor]]
|
||||
|
||||
def pathFromIndex(self, idx):
|
||||
@ -87,4 +111,4 @@ class TagCompleter(QCompleter):
|
||||
self.tags.remove("")
|
||||
except ValueError:
|
||||
pass
|
||||
return " ".join(self.tags)
|
||||
return " ".join(self.tags) + " "
|
Loading…
Reference in New Issue
Block a user