MCPcopy Index your code
hub / github.com/REditorSupport/vscode-R / extendSelection

Function extendSelection

src/selection.ts:209–287  ·  view source on GitHub ↗
(line: number, getLine: (line: number) => string, lineCount: number)

Source from the content-addressed store, hash-verified

207 * @param lineCount The number of lines in the document.
208 */
209export function extendSelection(line: number, getLine: (line: number) => string, lineCount: number): {
210 startLine: number;
211 endLine: number;
212} {
213 const lc = new LineCache(getLine, lineCount);
214 const getLineFromCache = (x: number) => lc.getLineFromCache(x);
215 const getEndsInOperatorFromCache = (x: number) => lc.getEndsInOperatorFromCache(x);
216 let lookingForward = true;
217 /* poss[1] is the farthest point reached looking forward from line,
218 and poss[0] is the farthest point reached looking backward from line. */
219 const poss = { 0: new PositionNeg(line, 0), 1: new PositionNeg(line, -1) };
220 const flagsFinish = { 0: false, 1: false }; // 1 represents looking forward, 0 represents looking back.
221 let flagAbort = false;
222 const unmatched = { 0: [] as string[], 1: [] as string[] };
223 let curChar = '';
224 let quoteChar = '';
225 while (!flagAbort && !(flagsFinish[0] && flagsFinish[1])) {
226 const { nextChar, nextPos, isEndOfCodeLine, isEndOfFile } = getNextChar(
227 poss[lookingForward ? 1 : 0],
228 lookingForward,
229 getLineFromCache,
230 getEndsInOperatorFromCache,
231 lineCount
232 );
233 poss[lookingForward ? 1 : 0] = nextPos;
234 if (quoteChar === '') {
235 if (isQuote(nextChar)) {
236 quoteChar = nextChar;
237 } else {
238 if (isBracket(nextChar, lookingForward)) {
239 unmatched[lookingForward ? 1 : 0].push(nextChar);
240 } else if (isBracket(nextChar, !lookingForward)) {
241 if (unmatched[lookingForward ? 1 : 0].length === 0) {
242 lookingForward = !lookingForward;
243 unmatched[lookingForward ? 1 : 0].push(nextChar);
244 flagsFinish[lookingForward ? 1 : 0] = false;
245 } else if (!doBracketsMatch(nextChar, unmatched[lookingForward ? 1 : 0].pop() ?? '')) {
246 flagAbort = true;
247 }
248 }
249 }
250 } else {
251 if (nextChar === quoteChar) {
252 if (lookingForward) {
253 if (curChar !== '\\') {
254 quoteChar = '';
255 }
256 } else {
257 const next = getNextChar(poss[lookingForward ? 1 : 0],
258 lookingForward,
259 getLineFromCache,
260 getEndsInOperatorFromCache,
261 lineCount);
262 if (next.nextChar !== '\\') {
263 quoteChar = '';
264 }
265 }
266 }

Callers 3

getSelectionFunction · 0.85

Calls 4

getNextCharFunction · 0.85
isBracketFunction · 0.85
doBracketsMatchFunction · 0.85
isQuoteFunction · 0.70

Tested by

no test coverage detected