[ui] Selection of text for copy of text attribute fixed

If there is no text selected, then it copies all the attribute, otherwise it copies only the selected text.
This commit is contained in:
Aurore LAFAURIE 2024-05-23 16:55:29 +02:00
parent e3e25e677e
commit dd7e19dd2c

View file

@ -211,9 +211,9 @@ RowLayout {
text: attribute.value text: attribute.value
selectByMouse: true selectByMouse: true
onEditingFinished: setTextFieldAttribute(text) onEditingFinished: setTextFieldAttribute(text)
persistentSelection: true
onAccepted: { onAccepted: {
setTextFieldAttribute(text) setTextFieldAttribute(text)
root.forceActiveFocus()
} }
Component.onDestruction: { Component.onDestruction: {
if (activeFocus) if (activeFocus)
@ -232,15 +232,11 @@ RowLayout {
} }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.AllButtons acceptedButtons: Qt.RightButton
onClicked: { onClicked: {
if (mouse.button == Qt.RightButton) {
var menu = menuCopy.createObject(parameterLabel) var menu = menuCopy.createObject(parameterLabel)
menu.parent = parameterLabel menu.parent = parameterLabel
menu.popup() menu.popup()
} else {
textField.forceActiveFocus()
}
} }
property Component menuCopy : Menu { property Component menuCopy : Menu {
@ -248,8 +244,10 @@ RowLayout {
text: "Copy" text: "Copy"
enabled: attribute.value != "" enabled: attribute.value != ""
onTriggered: { onTriggered: {
Clipboard.clear() // if no selection, select all
Clipboard.setText(attribute.value) if (textField.selectionStart === textField.selectionEnd)
textField.selectAll()
textField.copy()
} }
} }
MenuItem { MenuItem {