From 0c85aed04adf1ab78f61bcd1f6e609850011de48 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Wed, 30 Aug 2017 12:49:04 +0200 Subject: [PATCH 1/5] Navigate through tag autocompletions with Ctrl+Tab --- aqt/tagedit.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/aqt/tagedit.py b/aqt/tagedit.py index 85c83cb9e..e6a6d9c07 100644 --- a/aqt/tagedit.py +++ b/aqt/tagedit.py @@ -36,6 +36,16 @@ class TagEdit(QLineEdit): self.showCompleter() def keyPressEvent(self, evt): + if (evt.key() == Qt.Key_Tab and evt.modifiers() & Qt.ControlModifier): + if not self.completer.popup().isVisible(): + self.showCompleter() + # select next completion + 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): self.hideCompleter() QWidget.keyPressEvent(self, evt) From 153849c01ba9aeb8c15c84dd34c6d1b9b47f3e46 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Wed, 30 Aug 2017 13:11:03 +0200 Subject: [PATCH 2/5] Apply first tag autosuggestion with Enter/Return --- aqt/tagedit.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/aqt/tagedit.py b/aqt/tagedit.py index e6a6d9c07..8603a90eb 100644 --- a/aqt/tagedit.py +++ b/aqt/tagedit.py @@ -37,9 +37,9 @@ class TagEdit(QLineEdit): def keyPressEvent(self, evt): if (evt.key() == Qt.Key_Tab and evt.modifiers() & Qt.ControlModifier): + # select next completion if not self.completer.popup().isVisible(): self.showCompleter() - # select next completion index = self.completer.currentIndex() self.completer.popup().setCurrentIndex(index) cur_row = index.row() @@ -47,6 +47,12 @@ class TagEdit(QLineEdit): 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 From a7cdff6d9634c476f58e92d33d4262cdf9bf7b3d Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Wed, 30 Aug 2017 13:13:10 +0200 Subject: [PATCH 3/5] Invoke autosuggestion pop-up with arrow-key up/down --- aqt/tagedit.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aqt/tagedit.py b/aqt/tagedit.py index 8603a90eb..2236f901e 100644 --- a/aqt/tagedit.py +++ b/aqt/tagedit.py @@ -36,6 +36,11 @@ 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(): From e2373248731f3346f61cf18d2ef861a9c8929679 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Wed, 30 Aug 2017 14:19:15 +0200 Subject: [PATCH 4/5] Show new autosuggestions on typing space --- aqt/tagedit.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/aqt/tagedit.py b/aqt/tagedit.py index 2236f901e..e57c5410c 100644 --- a/aqt/tagedit.py +++ b/aqt/tagedit.py @@ -91,12 +91,14 @@ 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) + self.cursor = stripped_tags.count(" ", 0, p) + if tags.endswith(" "): + self.cursor += 1 return [self.tags[self.cursor]] def pathFromIndex(self, idx): From 8d6507c06234e684e197bb1ca77f43d1501d6aba Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Wed, 30 Aug 2017 14:52:58 +0200 Subject: [PATCH 5/5] Space-separate inserted tags New completions now show up after hitting space again --- aqt/tagedit.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/aqt/tagedit.py b/aqt/tagedit.py index e57c5410c..547e9055e 100644 --- a/aqt/tagedit.py +++ b/aqt/tagedit.py @@ -96,9 +96,10 @@ class TagCompleter(QCompleter): self.tags = self.edit.col.tags.split(stripped_tags) self.tags.append("") p = self.edit.cursorPosition() - self.cursor = stripped_tags.count(" ", 0, p) - if tags.endswith(" "): - self.cursor += 1 + 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): @@ -110,4 +111,4 @@ class TagCompleter(QCompleter): self.tags.remove("") except ValueError: pass - return " ".join(self.tags) + return " ".join(self.tags) + " " \ No newline at end of file