Skip to content

Commit 1a373d5

Browse files
sync: from linuxdeepin/dtkdeclarative
Synchronize source files from linuxdeepin/dtkdeclarative. Source-pull-request: linuxdeepin/dtkdeclarative#522
1 parent 8ee14f4 commit 1a373d5

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

qt6/src/qml/TextField.qml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ T.TextField {
1212
property D.Palette placeholderTextPalette: DS.Style.edit.placeholderText
1313
placeholderTextColor: D.ColorSelector.placeholderTextPalette
1414
property alias backgroundColor: panel.backgroundColor
15+
property bool canCopy: control.selectedText.length && control.echoMode === TextInput.Normal
16+
property bool canCut: !control.readonly && control.selectedText.length && control.echoMode === TextInput.Normal
1517
// alert control properties
1618
property alias alertText: panel.alertText
1719
property alias alertDuration: panel.alertDuration
@@ -77,14 +79,14 @@ T.TextField {
7779
{
7880
text: qsTr("Copy")
7981
onTriggered: control.copy()
80-
enabled: control.selectedText.length && control.echoMode === TextInput.Normal
82+
enabled: canCopy
8183
}
8284

8385
MenuItem
8486
{
8587
text: qsTr("Cut")
8688
onTriggered: control.cut()
87-
enabled: !control.readonly && control.selectedText.length && control.echoMode === TextInput.Normal
89+
enabled: canCut
8890
}
8991

9092
MenuItem
@@ -116,4 +118,18 @@ T.TextField {
116118
}
117119
}
118120

121+
Keys.enabled: !canCopy || !canCut
122+
Keys.onPressed: function(event) {
123+
if (event.matches(StandardKey.Copy)) {
124+
if (!canCopy) {
125+
event.accepted = true
126+
return
127+
}
128+
} else if (event.matches(StandardKey.Cut)) {
129+
if (!canCut) {
130+
event.accepted = true
131+
return
132+
}
133+
}
134+
}
119135
}

0 commit comments

Comments
 (0)