fix(StatusSeedPhraseInput): fix interactions in SeedInput

This commit is contained in:
Jonathan Rainville 2022-05-04 15:54:09 -04:00
parent 32c5f7f8df
commit 0922cf507a
1 changed files with 40 additions and 12 deletions

View File

@ -98,6 +98,11 @@ Item {
*/ */
signal editClicked() signal editClicked()
function setWord(word) {
seedWordInput.ignoreTextChange = true
seedWordInput.input.edit.text = word
}
onActiveFocusChanged: { onActiveFocusChanged: {
if (root.activeFocus) { if (root.activeFocus) {
seedWordInput.input.edit.forceActiveFocus(); seedWordInput.input.edit.forceActiveFocus();
@ -105,6 +110,8 @@ Item {
} }
StatusInput { StatusInput {
property bool ignoreTextChange: false
id: seedWordInput id: seedWordInput
implicitWidth: parent.width implicitWidth: parent.width
implicitHeight: parent.height implicitHeight: parent.height
@ -117,7 +124,12 @@ Item {
Theme.palette.primaryColor1 : Theme.palette.baseColor1 Theme.palette.primaryColor1 : Theme.palette.baseColor1
font.pixelSize: 15 font.pixelSize: 15
} }
input.acceptReturn: true
onTextChanged: { onTextChanged: {
if (ignoreTextChange) {
ignoreTextChange = false
return
}
filteredList.clear(); filteredList.clear();
if (text !== "") { if (text !== "") {
for (var i = 0; i < inputList.count; i++) { for (var i = 0; i < inputList.count; i++) {
@ -126,9 +138,9 @@ Item {
} }
} }
seedSuggestionsList.model = filteredList; seedSuggestionsList.model = filteredList;
if ((text.length >= 3) && (filteredList.count === 1) && if (filteredList.count === 1 && input.edit.keyEvent !== Qt.Key_Backspace
((input.edit.keyEvent !== Qt.Key_Backspace) && (input.edit.keyEvent !== Qt.Key_Delete))) { && input.edit.keyEvent !== Qt.Key_Delete
seedWordInput.text = filteredList.get(0).seedWord.trim(); && filteredList.get(0).seedWord.trim() === seedWordInput.text) {
seedWordInput.input.edit.cursorPosition = seedWordInput.text.length; seedWordInput.input.edit.cursorPosition = seedWordInput.text.length;
seedSuggestionsList.model = 0; seedSuggestionsList.model = 0;
root.doneInsertingWord(seedWordInput.text); root.doneInsertingWord(seedWordInput.text);
@ -138,11 +150,19 @@ Item {
} }
} }
onKeyPressed: { onKeyPressed: {
if (input.edit.keyEvent === Qt.Key_Tab) { if (input.edit.keyEvent === Qt.Key_Tab || input.edit.keyEvent === Qt.Key_Return || input.edit.keyEvent === Qt.Key_Enter) {
if (text.length != 0){ if (!!text && seedSuggestionsList.count > 0) {
root.doneInsertingWord(seedWordInput.text); seedSuggestionsList.completeWordFill(filteredList.get(seedSuggestionsList.currentIndex).seedWord)
event.accepted = true
return
} }
} }
if (input.edit.keyEvent === Qt.Key_Down) {
seedSuggestionsList.incrementCurrentIndex()
}
if (input.edit.keyEvent === Qt.Key_Up) {
seedSuggestionsList.decrementCurrentIndex()
}
root.keyPressed(event); root.keyPressed(event);
} }
onEditClicked: { onEditClicked: {
@ -184,6 +204,16 @@ Item {
anchors.topMargin: 8 anchors.topMargin: 8
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: 8 anchors.bottomMargin: 8
onCountChanged: {
seedSuggestionsList.currentIndex = 0
}
function completeWordFill(seedWord) {
seedWordInput.input.edit.text = seedWord.trim();
seedWordInput.input.edit.cursorPosition = seedWordInput.text.length;
}
clip: true clip: true
ScrollBar.vertical: ScrollBar { } ScrollBar.vertical: ScrollBar { }
delegate: Item { delegate: Item {
@ -193,7 +223,8 @@ Item {
Rectangle { Rectangle {
width: seedSuggestionsList.width width: seedSuggestionsList.width
height: parent.height height: parent.height
color: mouseArea.containsMouse? Theme.palette.primaryColor1 : "transparent" color: mouseArea.containsMouse || index === seedSuggestionsList.currentIndex ?
Theme.palette.primaryColor1 : "transparent"
} }
StatusBaseText { StatusBaseText {
id: suggWord id: suggWord
@ -212,10 +243,7 @@ Item {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
hoverEnabled: true hoverEnabled: true
onClicked: { onClicked: {
seedWordInput.input.edit.text = seedWord.trim(); seedSuggestionsList.completeWordFill(seedWord)
seedWordInput.input.edit.cursorPosition = seedWordInput.text.length;
root.doneInsertingWord(seedWordInput.text);
seedSuggestionsList.model = 0;
} }
} }
} }