MCPcopy Create free account
hub / github.com/cursorless-dev/cursorless / selectWithLeadingDelimiter

Function selectWithLeadingDelimiter

src/util/nodeSelectors.ts:114–151  ·  view source on GitHub ↗
(...delimiters: string[])

Source from the content-addressed store, hash-verified

112}
113
114export function selectWithLeadingDelimiter(...delimiters: string[]) {
115 return function (editor: TextEditor, node: SyntaxNode): SelectionWithContext {
116 const firstSibling = node.previousSibling;
117 const secondSibling = firstSibling?.previousSibling;
118 let leadingDelimiterRange;
119 if (firstSibling) {
120 if (delimiters.includes(firstSibling.type)) {
121 // Second sibling exists. Terminate before it.
122 if (secondSibling) {
123 leadingDelimiterRange = makeRangeFromPositions(
124 secondSibling.endPosition,
125 node.startPosition
126 );
127 }
128 // First delimiter sibling exists. Terminate after it.
129 else {
130 leadingDelimiterRange = makeRangeFromPositions(
131 firstSibling.startPosition,
132 node.startPosition
133 );
134 }
135 }
136 // First sibling exists but is not the delimiter we are looking for. Terminate before it.
137 else {
138 leadingDelimiterRange = makeRangeFromPositions(
139 firstSibling.endPosition,
140 node.startPosition
141 );
142 }
143 }
144 return {
145 ...simpleSelectionExtractor(editor, node),
146 context: {
147 leadingDelimiterRange,
148 },
149 };
150 };
151}
152
153export function selectWithTrailingDelimiter(...delimiters: string[]) {
154 return function (editor: TextEditor, node: SyntaxNode): SelectionWithContext {

Callers 3

typeMatcherFunction · 0.90
valueMatcherFunction · 0.90
leadingMatcherFunction · 0.90

Calls 2

makeRangeFromPositionsFunction · 0.85
simpleSelectionExtractorFunction · 0.85

Tested by

no test coverage detected