gui: fix B2/B3 mouse handling in editable TextEdit
Handle events in onPressed instead of onClicked so they work with editable text. Remove propagateComposedEvents since we want to intercept middle/right clicks completely.
This commit is contained in:
parent
b119668965
commit
36e8b0abd3
|
|
@ -212,36 +212,21 @@ Column {
|
|||
anchors.fill: parent
|
||||
acceptedButtons: Qt.MiddleButton | Qt.RightButton
|
||||
cursorShape: Qt.IBeamCursor
|
||||
propagateComposedEvents: true
|
||||
|
||||
property bool leftHeld: false
|
||||
|
||||
onPressed: function(mouse) {
|
||||
// Check if this is a chord (B1 already held)
|
||||
if (mouse.buttons & Qt.LeftButton) {
|
||||
leftHeld = true
|
||||
if (mouse.button === Qt.MiddleButton) {
|
||||
// B1+B2 = cut (snarf)
|
||||
mainTextEdit.cut()
|
||||
mouse.accepted = true
|
||||
return
|
||||
} else if (mouse.button === Qt.RightButton) {
|
||||
// B1+B3 = paste
|
||||
mainTextEdit.paste()
|
||||
mouse.accepted = true
|
||||
return
|
||||
}
|
||||
}
|
||||
leftHeld = false
|
||||
mouse.accepted = false
|
||||
}
|
||||
|
||||
onClicked: function(mouse) {
|
||||
if (leftHeld) {
|
||||
leftHeld = false
|
||||
mouse.accepted = true
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (mouse.button === Qt.MiddleButton) {
|
||||
// B2: Execute selection as prompt
|
||||
var sel = mainTextEdit.selectedText
|
||||
|
|
@ -251,26 +236,20 @@ Column {
|
|||
mouse.accepted = true
|
||||
} else if (mouse.button === Qt.RightButton) {
|
||||
// B3: Plumb selection or word under cursor
|
||||
if (!plumber.available()) {
|
||||
mouse.accepted = true
|
||||
return
|
||||
}
|
||||
var sel = mainTextEdit.selectedText
|
||||
if (sel && sel.trim() !== "") {
|
||||
plumber.plumb(sel.trim(), sessionCwd())
|
||||
} else {
|
||||
// No selection - expand word at click position (acme-style)
|
||||
var pos = mainTextEdit.positionAt(mouse.x, mouse.y)
|
||||
var word = wordAtCursor(mainTextEdit, pos)
|
||||
if (word) plumber.plumb(word, sessionCwd())
|
||||
if (plumber.available()) {
|
||||
var sel = mainTextEdit.selectedText
|
||||
if (sel && sel.trim() !== "") {
|
||||
plumber.plumb(sel.trim(), sessionCwd())
|
||||
} else {
|
||||
// No selection - expand word at click position (acme-style)
|
||||
var pos = mainTextEdit.positionAt(mouse.x, mouse.y)
|
||||
var word = wordAtCursor(mainTextEdit, pos)
|
||||
if (word) plumber.plumb(word, sessionCwd())
|
||||
}
|
||||
}
|
||||
mouse.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
onReleased: {
|
||||
leftHeld = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -398,30 +377,15 @@ Column {
|
|||
anchors.fill: parent
|
||||
acceptedButtons: Qt.MiddleButton | Qt.RightButton
|
||||
cursorShape: Qt.IBeamCursor
|
||||
propagateComposedEvents: true
|
||||
|
||||
property bool leftHeld: false
|
||||
|
||||
onPressed: function(mouse) {
|
||||
if (mouse.buttons & Qt.LeftButton) {
|
||||
leftHeld = true
|
||||
if (mouse.button === Qt.MiddleButton) {
|
||||
textEdit.cut()
|
||||
mouse.accepted = true
|
||||
return
|
||||
} else if (mouse.button === Qt.RightButton) {
|
||||
textEdit.paste()
|
||||
mouse.accepted = true
|
||||
return
|
||||
}
|
||||
}
|
||||
leftHeld = false
|
||||
mouse.accepted = false
|
||||
}
|
||||
|
||||
onClicked: function(mouse) {
|
||||
if (leftHeld) {
|
||||
leftHeld = false
|
||||
mouse.accepted = true
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -433,25 +397,19 @@ Column {
|
|||
mouse.accepted = true
|
||||
} else if (mouse.button === Qt.RightButton) {
|
||||
// B3: Plumb selection or word under cursor
|
||||
if (!plumber.available()) {
|
||||
mouse.accepted = true
|
||||
return
|
||||
}
|
||||
var sel = textEdit.selectedText
|
||||
if (sel && sel.trim() !== "") {
|
||||
plumber.plumb(sel.trim(), sessionCwd())
|
||||
} else {
|
||||
var pos = textEdit.positionAt(mouse.x, mouse.y)
|
||||
var word = wordAtCursor(textEdit, pos)
|
||||
if (word) plumber.plumb(word, sessionCwd())
|
||||
if (plumber.available()) {
|
||||
var sel = textEdit.selectedText
|
||||
if (sel && sel.trim() !== "") {
|
||||
plumber.plumb(sel.trim(), sessionCwd())
|
||||
} else {
|
||||
var pos = textEdit.positionAt(mouse.x, mouse.y)
|
||||
var word = wordAtCursor(textEdit, pos)
|
||||
if (word) plumber.plumb(word, sessionCwd())
|
||||
}
|
||||
}
|
||||
mouse.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
onReleased: {
|
||||
leftHeld = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue