diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-03 21:11:30 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-04 12:54:23 +0200 |
| commit | fc3073f452e28733c3910ceda403531b3e17404d (patch) | |
| tree | 9abc7cebce905b2b6e5c7639f7c7fb0bf2659a11 /src/querycompleter.cpp | |
| parent | 1e587846a255592e5aab022c4e6e134d4ff64ed2 (diff) | |
| download | qtmaildir-fc3073f452e28733c3910ceda403531b3e17404d.tar.gz qtmaildir-fc3073f452e28733c3910ceda403531b3e17404d.zip | |
feat(completion): wire query completion into the main window
Adds the complete_query action, whose registration the assertion in
registerActions() has been demanding since keymap gained the name: a
known action nothing implements would have been a silently dead binding.
Also lands the QueryCompleter half of the manual trigger, which the
keymap commit left behind: triggerCompletion() and the focus-in filter
gated on completion_on_focus.
Tags refresh at startup, after a sync, and after a mutation introduces a
tag not already known, since that is the tag most likely to be typed
again. onAllTagsReady deliberately drops the generation the signal
carries: a tag list is not an ordered query result, so a later one is
always at least as good as an earlier one and discarding on staleness
could only throw away a good list.
Diffstat (limited to 'src/querycompleter.cpp')
| -rw-r--r-- | src/querycompleter.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/querycompleter.cpp b/src/querycompleter.cpp index 8457776..1a6f6de 100644 --- a/src/querycompleter.cpp +++ b/src/querycompleter.cpp @@ -360,6 +360,36 @@ QueryCompleter::QueryCompleter(QLineEdit *edit, const Config &config, this, [this](const QModelIndex &index) { acceptCompletion(index.data(Qt::DisplayRole).toString()); }); + + if (m_config.completionOnFocus()) + m_edit->installEventFilter(this); +} + +void QueryCompleter::triggerCompletion() +{ + if (!m_edit || !m_completer) + return; + + updateContext(); + if (m_context.kind == CompletionContext::None) + return; + + // The prefix must be set explicitly: complete() filters against whatever + // prefix QCompleter last derived from the line edit's full text, which is + // not the stem once a keyword or a range bound is in play. + m_completer->setCompletionPrefix(m_context.stem); + m_completer->complete(); +} + +bool QueryCompleter::eventFilter(QObject *watched, QEvent *event) +{ + // Only the empty-bar case: once there is text, ordinary typing has + // already driven completion. + if (watched == m_edit && event->type() == QEvent::FocusIn + && m_edit->text().isEmpty()) { + triggerCompletion(); + } + return QObject::eventFilter(watched, event); } void QueryCompleter::acceptCompletion(const QString &value) |
