summary refs log tree commit diff
path: root/src/TextInputWidget.cc
diff options
context:
space:
mode:
authorchristarazi <christarazi@users.noreply.github.com>2018-04-10 01:47:23 -0700
committermujx <mujx@users.noreply.github.com>2018-04-10 11:47:23 +0300
commit0b3029b3c48af4bf8aa302c28e66bce771213c94 (patch)
tree18835fdce3a88f58c898224c6eb30703fb9b7d63 /src/TextInputWidget.cc
parentHide emoji panel if it's not under the mouse cursor (diff)
downloadnheko-0b3029b3c48af4bf8aa302c28e66bce771213c94.tar.xz
Implement pressing tab to navigate auto completion (#294)
Fixes #287

* Fix pop-up not showing when less than max 

* Select suggestion by pressing Enter
Diffstat (limited to 'src/TextInputWidget.cc')
-rw-r--r--src/TextInputWidget.cc19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/TextInputWidget.cc b/src/TextInputWidget.cc

index fde4a061..459fcd51 100644 --- a/src/TextInputWidget.cc +++ b/src/TextInputWidget.cc
@@ -86,6 +86,16 @@ FilteredTextEdit::FilteredTextEdit(QWidget *parent) cursor.insertText(text); }); + // For cycling through the suggestions by hitting tab. + connect(this, + &FilteredTextEdit::cycleSuggestions, + &popup_, + &SuggestionsPopup::cycleThroughSuggestions); + connect(this, + &FilteredTextEdit::selectHoveredSuggestion, + &popup_, + &SuggestionsPopup::selectHoveredSuggestion); + previewDialog_.hide(); } @@ -128,10 +138,15 @@ FilteredTextEdit::keyPressEvent(QKeyEvent *event) if (popup_.isVisible()) { switch (event->key()) { + case Qt::Key_Tab: + emit cycleSuggestions(); + return; case Qt::Key_Enter: case Qt::Key_Return: + emit selectHoveredSuggestion(); + return; case Qt::Key_Escape: - case Qt::Key_Tab: + break; case Qt::Key_Space: case Qt::Key_Backtab: { closeSuggestions(); @@ -464,6 +479,8 @@ TextInputWidget::TextInputWidget(QWidget *parent) if (items.size() >= MaxPopupItems) std::advance(end, MaxPopupItems); + else if (items.size() > 0) + std::advance(end, items.size()); for (auto it = items.begin(); it != end; it++) { const auto user = it->second;