From: tobtoht Date: Mon, 14 Oct 2024 21:54:55 +0000 (+0200) Subject: wizard: don't add space if there is already one, never insert tab X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=849269f53f9cf0871c3934d541364f6d8a798c07;p=gamesguru%2Ffeather.git wizard: don't add space if there is already one, never insert tab --- diff --git a/src/components.h b/src/components.h index 17b2604b..558629ff 100644 --- a/src/components.h +++ b/src/components.h @@ -118,13 +118,4 @@ public: } }; -class SpaceCompleter : public QCompleter { -protected: - QString pathFromIndex(const QModelIndex &index) const override - { - QString completion = QCompleter::pathFromIndex(index); - return completion + ' '; - } -}; - #endif //FEATHER_COMPONENTS_H diff --git a/src/utils/textedit.cpp b/src/utils/textedit.cpp index aca282b9..c0379afd 100644 --- a/src/utils/textedit.cpp +++ b/src/utils/textedit.cpp @@ -89,6 +89,9 @@ void TextEdit::insertCompletion(const QString &completion) { tc.movePosition(QTextCursor::Left); tc.movePosition(QTextCursor::EndOfWord); tc.insertText(completion.right(extra)); + if (this->document()->characterAt(tc.position()) != ' ') { + tc.insertText(" "); + } setTextCursor(tc); } @@ -105,19 +108,28 @@ void TextEdit::focusInEvent(QFocusEvent *e) { } void TextEdit::keyPressEvent(QKeyEvent *e) { - if (c && c->popup()->isVisible()) { - // The following keys are forwarded by the completer to the widget - switch (e->key()) { - case Qt::Key_Enter: - case Qt::Key_Return: - case Qt::Key_Escape: - case Qt::Key_Tab: - case Qt::Key_Backtab: - e->ignore(); - return; // let the completer do default behavior - default: - break; - } + if (c) { + if (c->popup()->isVisible()) { + // The following keys are forwarded by the completer to the widget + switch (e->key()) { + case Qt::Key_Enter: + case Qt::Key_Return: + case Qt::Key_Escape: + case Qt::Key_Tab: + case Qt::Key_Backtab: + e->ignore(); + return; // let the completer do default behavior + default: + break; + } + } + else { + // Never insert a tab char if we have a completer + if (e->key() == Qt::Key_Tab) { + e->accept(); + return; + } + } } const bool isShortcut = (e->modifiers().testFlag(Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E diff --git a/src/wizard/PageWalletRestoreSeed.h b/src/wizard/PageWalletRestoreSeed.h index ed02550a..2d3367ca 100644 --- a/src/wizard/PageWalletRestoreSeed.h +++ b/src/wizard/PageWalletRestoreSeed.h @@ -43,7 +43,7 @@ private: int length; QStringList words; QStringListModel completerModel; - SpaceCompleter completer; + QCompleter completer; Seed::Type type; };