Skip to content

Commit b077c2e

Browse files
committed
Fix "inside" broken with mixed quote types (#3109)
When two ambiguous delimiters (like single quotes) matched, the stack truncation destroyed all entries above the match — including unrelated delimiter types (backticks) pushed between the matched pair. Use splice instead of truncation for ambiguous delimiters to preserve unrelated stack entries.
1 parent 0b037a4 commit b077c2e

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
languageId: plaintext
2+
command:
3+
version: 7
4+
spokenForm: change inside pair
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- {type: interiorOnly}
11+
- type: containingScope
12+
scopeType: {type: surroundingPair, delimiter: any}
13+
usePrePhraseSnapshot: true
14+
initialState:
15+
documentContents: |-
16+
aaa's `bbb 'ccc'`
17+
`ddd`
18+
selections:
19+
- anchor: {line: 1, character: 1}
20+
active: {line: 1, character: 1}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
aaa's `bbb 'ccc'`
25+
``
26+
selections:
27+
- anchor: {line: 1, character: 1}
28+
active: {line: 1, character: 1}

packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/getSurroundingPairOccurrences.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@ export function getSurroundingPairOccurrences(
4343

4444
const openingDelimiter = openingDelimitersStack[openingDelimiterIndex];
4545

46-
// Pop stack up to and including the opening delimiter
47-
openingDelimitersStack.length = openingDelimiterIndex;
46+
if (side === "unknown") {
47+
// For ambiguous delimiters (eg quotes), remove only the matched
48+
// entry so that unrelated delimiter types pushed between the
49+
// matched pair are preserved. See #3109.
50+
openingDelimitersStack.splice(openingDelimiterIndex, 1);
51+
} else {
52+
// For non-ambiguous delimiters (eg parentheses), truncate the
53+
// stack to enforce proper nesting.
54+
openingDelimitersStack.length = openingDelimiterIndex;
55+
}
4856

4957
result.push({
5058
delimiterName: delimiterName,

0 commit comments

Comments
 (0)