diff --git a/kde/gui/ChatBlockDelegate.qml b/kde/gui/ChatBlockDelegate.qml index eb2befd..ee3e297 100644 --- a/kde/gui/ChatBlockDelegate.qml +++ b/kde/gui/ChatBlockDelegate.qml @@ -395,6 +395,26 @@ Column { } } + function isQuote(ch) { + return ch === "'" || ch === '"' || ch === '`' + } + + // Scan forward for the next occurrence of a quote char + function findQuoteForward(text, startPos, quote) { + for (var pos = startPos; pos < text.length; pos++) { + if (text.charAt(pos) === quote) return pos + } + return -1 + } + + // Scan backward for the previous occurrence of a quote char + function findQuoteBackward(text, startPos, quote) { + for (var pos = startPos; pos >= 0; pos--) { + if (text.charAt(pos) === quote) return pos + } + return -1 + } + // Find matching closer, handling nesting function findCloser(text, startPos, opener, closer) { var depth = 1 @@ -475,6 +495,20 @@ Column { innerStart = cursorPos innerEnd = closerPos } + } else if (isQuote(rightCh)) { + // Quote to right: treat as opener, find next matching quote forward + var qClose = findQuoteForward(text, cursorPos + 1, rightCh) + if (qClose >= 0) { + innerStart = cursorPos + 1 + innerEnd = qClose + } + } else if (isQuote(leftCh)) { + // Quote to left: treat as closer, find previous matching quote backward + var qOpen = findQuoteBackward(text, cursorPos - 2, leftCh) + if (qOpen >= 0) { + innerStart = qOpen + 1 + innerEnd = cursorPos - 1 + } } if (innerStart >= 0 && innerEnd >= innerStart) {