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

Function getLine

src/processTargets/processMark.ts:156–195  ·  view source on GitHub ↗
(linePosition: LineNumberPosition)

Source from the content-addressed store, hash-verified

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(

Callers 1

processLineNumberFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected