diff --git a/data/fixtures/scopes/plaintext/surroundingPair/surroundingPair7.scope b/data/fixtures/scopes/plaintext/surroundingPair/surroundingPair7.scope new file mode 100644 index 0000000000..8eec1cf6d3 --- /dev/null +++ b/data/fixtures/scopes/plaintext/surroundingPair/surroundingPair7.scope @@ -0,0 +1,75 @@ +aaa's `bbb 'ccc'` +`ddd` +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:3-0:12 + >---------< +0| aaa's `bbb 'ccc'` + +[#1 Interior: Content] = 0:4-0:10 + >------< +0| aaa's `bbb 'ccc'` +[#1 Interior: Removal] = 0:4-0:11 + >-------< +0| aaa's `bbb 'ccc'` + +[#1 Boundary L] = 0:3-0:4 + >-< +0| aaa's `bbb 'ccc'` + +[#1 Boundary R] = 0:11-0:12 + >-< +0| aaa's `bbb 'ccc'` + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Domain] = 0:6-0:17 + >-----------< +0| aaa's `bbb 'ccc'` + +[#2 Removal] = 0:5-0:17 + >------------< +0| aaa's `bbb 'ccc'` + +[#2 Leading delimiter] = 0:5-0:6 + >-< +0| aaa's `bbb 'ccc'` + +[#2 Interior] = 0:7-0:16 + >---------< +0| aaa's `bbb 'ccc'` + +[#2 Boundary L] = 0:6-0:7 + >-< +0| aaa's `bbb 'ccc'` + +[#2 Boundary R] = 0:16-0:17 + >-< +0| aaa's `bbb 'ccc'` + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = +[#3 Domain] = 1:0-1:5 + >-----< +1| `ddd` + +[#3 Interior] = 1:1-1:4 + >---< +1| `ddd` + +[#3 Boundary L] = 1:0-1:1 + >-< +1| `ddd` + +[#3 Boundary R] = 1:4-1:5 + >-< +1| `ddd` + +[#3 Insertion delimiter] = " " diff --git a/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/getSurroundingPairOccurrences.ts b/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/getSurroundingPairOccurrences.ts index 7f33695a9c..2f2f894c73 100644 --- a/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/getSurroundingPairOccurrences.ts +++ b/packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/SurroundingPairScopeHandler/getSurroundingPairOccurrences.ts @@ -43,8 +43,16 @@ export function getSurroundingPairOccurrences( const openingDelimiter = openingDelimitersStack[openingDelimiterIndex]; - // Pop stack up to and including the opening delimiter - openingDelimitersStack.length = openingDelimiterIndex; + if (side === "unknown") { + // For ambiguous delimiters (eg quotes), remove only the matched + // entry so that unrelated delimiter types pushed between the + // matched pair are preserved. See #3109. + openingDelimitersStack.splice(openingDelimiterIndex, 1); + } else { + // For non-ambiguous delimiters (eg parentheses), truncate the + // stack to enforce proper nesting. + openingDelimitersStack.length = openingDelimiterIndex; + } result.push({ delimiterName: delimiterName,