diff --git a/kde/gui/ChatBlockDelegate.qml b/kde/gui/ChatBlockDelegate.qml index 41d0672..16f3ac8 100644 --- a/kde/gui/ChatBlockDelegate.qml +++ b/kde/gui/ChatBlockDelegate.qml @@ -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 } }