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

Method formatBlock

src/ide.ts:1374–1415  ·  view source on GitHub ↗
(source:{type:string})

Source from the content-addressed store, hash-verified

1372 }
1373
1374 formatBlock(source:{type:string}) {
1375 this.finalizeLastHistoryEntry();
1376 let doc = this.cm.getDoc();
1377 this.cm.operation(() => {
1378 let from = {line: doc.getCursor("from").line, ch: 0};
1379 let to = {line: doc.getCursor("to").line + 1, ch: 0};
1380
1381 if(doc.getLine(to.line) !== "") {
1382 let cursor = doc.getCursor();
1383 doc.replaceRange("\n", to, to, "+normalize");
1384 doc.setCursor(cursor);
1385 }
1386
1387 // Determine if a block span in this range already exists.
1388 let exists:Span|undefined;
1389 let existing = this.findSpansAt(from, source.type);
1390 for(let span of existing) {
1391 let loc = span.find();
1392 if(!loc) continue;
1393 exists = span;
1394 break;
1395 }
1396
1397 // If the span already exists, we mean to clear it.
1398 if(exists) {
1399 exists.clear();
1400
1401 // We're creating a new span.
1402 } else {
1403
1404 // Block formats are exclusive, so we clear intersecting spans of other types.
1405 let spans = this.findSpans(doc.posFromIndex(doc.indexFromPos(from) - 1), to);
1406 for(let span of spans) {
1407 if(span.isEditorControlled()) {
1408 span.clear();
1409 }
1410 }
1411
1412 this.formatSpan(from, to, source);
1413 }
1414 });
1415 }
1416
1417 trackDenormalized(span:Span) {
1418 if(span.isDenormalized) {

Callers 1

formatMethod · 0.95

Calls 15

findSpansAtMethod · 0.95
findSpansMethod · 0.95
formatSpanMethod · 0.95
getDocMethod · 0.80
operationMethod · 0.80
getCursorMethod · 0.80
getLineMethod · 0.80
replaceRangeMethod · 0.80
setCursorMethod · 0.80
posFromIndexMethod · 0.80
indexFromPosMethod · 0.80

Tested by

no test coverage detected