MCPcopy
hub / github.com/witheve/Eve / formatLine

Method formatLine

src/ide.ts:1327–1372  ·  view source on GitHub ↗
(source:{type:string, level?:number, listData?: {type:"ordered"|"bullet", start?: number}})

Source from the content-addressed store, hash-verified

1325 }
1326
1327 formatLine(source:{type:string, level?:number, listData?: {type:"ordered"|"bullet", start?: number}}) {
1328 this.finalizeLastHistoryEntry();
1329 let doc = this.cm.getDoc();
1330 this.cm.operation(() => {
1331 let from = doc.getCursor("from");
1332 let to = doc.getCursor("to");
1333
1334 // No editor-controlled span may be created within a codeblock.
1335 // @NOTE: This feels like a minor layor violation.
1336 if(from.line !== to.line && this.findSpans(from, to, "code_block").length || this.findSpansAt(from, "code_block").length) return;
1337
1338 let existing:Span[] = [];
1339 let formatted = false;
1340 for(let line = from.line, end = to.line; line <= end; line++) {
1341 let cur = {line, ch: 0};
1342
1343 // Line formats are exclusive, so we clear intersecting line spans of other types.
1344 let spans = this.findSpansAt(cur);
1345 for(let span of spans) {
1346 if(span.isLine() && span.source.type !== source.type) {
1347 span.clear();
1348 }
1349 }
1350
1351 spans = this.findSpansAt(cur, source.type);
1352 // If this line isn't already formatted to this type, format it.
1353 if(!spans.length) {
1354 this.formatSpan(cur, cur, source);
1355 formatted = true;
1356 // Otherwise store the span. We may need to clear them if we intend to unformat the selection.
1357 } else {
1358 existing.push.apply(existing, spans);
1359 }
1360 }
1361
1362 // If no new lines were formatted, we mean to clear the existing format.
1363 if(!formatted) {
1364 for(let span of existing) {
1365 span.clear();
1366 }
1367 }
1368
1369 this.finalizeLastHistoryEntry();
1370 this.refresh();
1371 });
1372 }
1373
1374 formatBlock(source:{type:string}) {
1375 this.finalizeLastHistoryEntry();

Callers 1

formatMethod · 0.95

Calls 11

findSpansMethod · 0.95
findSpansAtMethod · 0.95
formatSpanMethod · 0.95
refreshMethod · 0.95
getDocMethod · 0.80
operationMethod · 0.80
getCursorMethod · 0.80
isLineMethod · 0.80
clearMethod · 0.65
applyMethod · 0.45

Tested by

no test coverage detected