Skip to content

Commit

Permalink
wizard: don't add space if there is already one, never insert tab
Browse files Browse the repository at this point in the history
  • Loading branch information
tobtoht committed Oct 14, 2024
1 parent 5acbd9a commit 849269f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
9 changes: 0 additions & 9 deletions src/components.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,4 @@ class U32Validator : public QValidator {
}
};

class SpaceCompleter : public QCompleter {
protected:
QString pathFromIndex(const QModelIndex &index) const override
{
QString completion = QCompleter::pathFromIndex(index);
return completion + ' ';
}
};

#endif //FEATHER_COMPONENTS_H
38 changes: 25 additions & 13 deletions src/utils/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/wizard/PageWalletRestoreSeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PageWalletRestoreSeed : public QWizardPage
int length;
QStringList words;
QStringListModel completerModel;
SpaceCompleter completer;
QCompleter completer;
Seed::Type type;
};

Expand Down

0 comments on commit 849269f

Please sign in to comment.