gui: extend double-click pair selection to quotes
selectBracketPair now also handles '' "" `` quote pairs. Since a quote char opens and closes with the same glyph, a quote to the right of the cursor scans forward for its match, and a quote to the left scans backward.
This commit is contained in:
parent
1cfa424220
commit
86977b3ca3
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue