[SendModal] fix pasting an address

- validate input also when pasting via the button (extract to a common
function)
- show the Paste button only when the input is empty and we have sth to
paste actually and prevent it from stealing focus
- upon clicking the Paste button, put focus on the input field
- after pasting, set the cursor past the end of the text

Fixes #14576
This commit is contained in:
Lukáš Tinkl 2024-06-27 12:57:52 +02:00 committed by Lukáš Tinkl
parent 5c349d1938
commit 13815bf81c
1 changed files with 26 additions and 22 deletions

View File

@ -104,8 +104,10 @@ Loader {
let result = store.splitAndFormatAddressPrefix(address, !root.isBridgeTx && !isCollectiblesTransfer)
if(!!result.address) {
root.addressText = result.address
if(!!root.item.input)
if(!!root.item.input) {
root.item.input.text = result.formattedText
root.item.input.edit.cursorPosition = root.item.input.edit.length
}
}
root.recalculateRoutesAndFees()
}
@ -183,11 +185,22 @@ Loader {
input.background.color: Theme.palette.indirectColor1
input.background.border.width: 0
input.implicitHeight: 56
input.clearable: root.interactive
input.clearable: false // custom button below
input.edit.readOnly: !root.interactive
multiline: false
input.edit.textFormat: TextEdit.RichText
text: addressText
text: root.addressText
function validateInput() {
const plainText = store.plainText(recipientInput.text)
root.isLoading()
if (Utils.isValidEns(plainText)) {
d.isPending = true
d.resolveENS(plainText)
} else {
d.waitTimer.restart()
}
}
input.rightComponent: RowLayout {
StatusButton {
@ -195,8 +208,14 @@ Loader {
borderColor: Theme.palette.primaryColor1
size: StatusBaseButton.Size.Tiny
text: qsTr("Paste")
visible: !store.plainText(recipientInput.text)
onClicked: recipientInput.input.edit.paste()
visible: recipientInput.input.edit.length === 0 && recipientInput.input.edit.canPaste
focusPolicy: Qt.NoFocus
onClicked: {
recipientInput.input.edit.forceActiveFocus()
recipientInput.input.edit.paste()
recipientInput.input.edit.cursorPosition = recipientInput.input.edit.length
recipientInput.validateInput()
}
}
StatusIcon {
Layout.preferredWidth: 16
@ -206,7 +225,7 @@ Loader {
visible: root.ready
}
StatusClearButton {
visible: !!store.plainText(recipientInput.text)
visible: recipientInput.input.edit.length !== 0 && root.interactive
onClicked: {
recipientInput.input.edit.clear()
d.clearValues()
@ -214,22 +233,7 @@ Loader {
}
}
Keys.onTabPressed: event.accepted = true
Keys.onReleased: {
let plainText = store.plainText(input.edit.text)
if(!plainText) {
d.clearValues()
}
else {
root.isLoading()
if(Utils.isValidEns(plainText)) {
d.isPending = true
d.resolveENS(plainText)
}
else {
d.waitTimer.restart()
}
}
}
Keys.onReleased: recipientInput.validateInput()
}
}