]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
wizard: don't add space if there is already one, never insert tab
authortobtoht <tob@featherwallet.org>
Mon, 14 Oct 2024 21:54:55 +0000 (23:54 +0200)
committertobtoht <tob@featherwallet.org>
Mon, 14 Oct 2024 21:56:11 +0000 (23:56 +0200)
src/components.h
src/utils/textedit.cpp
src/wizard/PageWalletRestoreSeed.h

index 17b2604b87eb6ad4e4fc5da3b79b3e83f249802e..558629ff3314679370ba8b955a41fd09a37ad4b2 100644 (file)
@@ -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
index aca282b9fbaadd4da0e084e63e34bd9edcc98cad..c0379afd8e5d3f0b7a61696418f9ac003e6439e2 100644 (file)
@@ -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
index ed02550a472afadc4a25299a793456a2a0b56475..2d3367caab72d9c28e1eda84133dd9573b42a8a2 100644 (file)
@@ -43,7 +43,7 @@ private:
         int length;
         QStringList words;
         QStringListModel completerModel;
-        SpaceCompleter completer;
+        QCompleter completer;
         Seed::Type type;
     };