gui: do word select ourselves on double-click
The overlay MouseArea swallows the B1 double-click, so returning mouse.accepted=false did not make the TextEdit perform its native word select — a non-delimiter double-click selected nothing. Now the handler selects the word directly via selectWordAt when no bracket or quote pair is under the cursor, so double-click is deterministic: delimiter -> pair select, otherwise -> word select.
This commit is contained in:
parent
5170361e90
commit
4b2c14943d
|
|
@ -221,12 +221,13 @@ Column {
|
|||
|
||||
onDoubleClicked: function(mouse) {
|
||||
if (mouse.button === Qt.LeftButton) {
|
||||
// Try bracket-pair selection; fall through to word select if no bracket
|
||||
if (selectBracketPair(mainTextEdit, mouse.x, mouse.y)) {
|
||||
mouse.accepted = true
|
||||
} else {
|
||||
mouse.accepted = false // let TextEdit do word select
|
||||
// Delimiter under cursor: select the pair.
|
||||
// Otherwise select the word ourselves (the overlay
|
||||
// swallows the event, so TextEdit won't do it).
|
||||
if (!selectBracketPair(mainTextEdit, mouse.x, mouse.y)) {
|
||||
selectWordAt(mainTextEdit, mouse.x, mouse.y)
|
||||
}
|
||||
mouse.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -382,6 +383,27 @@ Column {
|
|||
}
|
||||
}
|
||||
|
||||
// Select the plain word under the mouse (double-click word select).
|
||||
// Uses a word charset, not acme's broader isfilec, so a double-click
|
||||
// behaves like a normal editor word select.
|
||||
function selectWordAt(textEdit, mouseX, mouseY) {
|
||||
var cursorPos = textEdit.positionAt(mouseX, mouseY)
|
||||
var text = textEdit.getText(0, textEdit.length)
|
||||
if (cursorPos < 0 || cursorPos > text.length) return
|
||||
|
||||
function isword(ch) {
|
||||
return /[A-Za-z0-9_]/.test(ch)
|
||||
}
|
||||
|
||||
var start = cursorPos
|
||||
while (start > 0 && isword(text.charAt(start - 1))) start--
|
||||
var end = cursorPos
|
||||
while (end < text.length && isword(text.charAt(end))) end++
|
||||
|
||||
if (start === end) return
|
||||
textEdit.select(start, end)
|
||||
}
|
||||
|
||||
// Bracket pairs for double-click selection
|
||||
function matchingBracket(ch) {
|
||||
switch (ch) {
|
||||
|
|
@ -545,11 +567,10 @@ Column {
|
|||
|
||||
onDoubleClicked: function(mouse) {
|
||||
if (mouse.button === Qt.LeftButton) {
|
||||
if (selectBracketPair(textEdit, mouse.x, mouse.y)) {
|
||||
mouse.accepted = true
|
||||
} else {
|
||||
mouse.accepted = false
|
||||
if (!selectBracketPair(textEdit, mouse.x, mouse.y)) {
|
||||
selectWordAt(textEdit, mouse.x, mouse.y)
|
||||
}
|
||||
mouse.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue