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

Function processLineNumber

src/processTargets/processMark.ts:154–207  ·  view source on GitHub ↗
(context: ProcessedTargetsContext, mark: LineNumber)

Source from the content-addressed store, hash-verified

152}
153
154function processLineNumber(context: ProcessedTargetsContext, mark: LineNumber) {
155 const editor = context.currentEditor!;
156 const getLine = (linePosition: LineNumberPosition) => {
157 switch (linePosition.type) {
158 case "absolute":
159 return linePosition.lineNumber;
160 case "relative":
161 return editor.selection.active.line + linePosition.lineNumber;
162 case "modulo100":
163 const stepSize = 100;
164 const startLine = editor.visibleRanges[0].start.line;
165 const endLine =
166 editor.visibleRanges[editor.visibleRanges.length - 1].end.line;
167 const base = Math.floor(startLine / stepSize) * stepSize;
168 const visibleLines = [];
169 const invisibleLines = [];
170 let lineNumber = base + linePosition.lineNumber;
171 while (lineNumber <= endLine) {
172 if (lineNumber >= startLine) {
173 const visible = editor.visibleRanges.find(
174 (r) => lineNumber >= r.start.line && lineNumber <= r.end.line
175 );
176 if (visible) {
177 visibleLines.push(lineNumber);
178 } else {
179 invisibleLines.push(lineNumber);
180 }
181 }
182 lineNumber += stepSize;
183 }
184 if (visibleLines.length === 1) {
185 return visibleLines[0];
186 }
187 if (visibleLines.length + invisibleLines.length > 1) {
188 throw new Error("Multiple lines matching");
189 }
190 if (invisibleLines.length === 1) {
191 return invisibleLines[0];
192 }
193 throw new Error("Line is not in viewport");
194 }
195 };
196 return [
197 {
198 selection: new Selection(
199 getLine(mark.anchor),
200 0,
201 getLine(mark.active),
202 0
203 ),
204 editor: context.currentEditor!,
205 },
206 ];
207}
208
209function isAlphaNum(text: string) {
210 return /^\w+$/.test(text);

Callers 1

processMark.tsFile · 0.85

Calls 1

getLineFunction · 0.85

Tested by

no test coverage detected