MCPcopy Create free account
hub / github.com/witheve/Eve / formatInline

Method formatInline

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

Source from the content-addressed store, hash-verified

1283 }
1284
1285 formatInline(source:{type:string}) {
1286 this.finalizeLastHistoryEntry();
1287 let doc = this.cm.getDoc();
1288 this.cm.operation(() => {
1289 let from = doc.getCursor("from");
1290 from = {line: from.line, ch: adjustToWordBoundary(from.ch, doc.getLine(from.line), "left")};
1291
1292 // If we have a selection, format it, expanded to the nearest word boundaries.
1293 // Or, if we're currently in a word, format the word.
1294 if(doc.somethingSelected() || from.ch !== doc.getCursor("from").ch) {
1295 let to = doc.getCursor("to");
1296 to = {line: to.line, ch: adjustToWordBoundary(to.ch, doc.getLine(to.line), "right")};
1297
1298 // No editor-controlled span may be created within a codeblock.
1299 // @NOTE: This feels like a minor layor violation.
1300 if(from.line !== to.line && this.findSpans(from, to, "code_block").length || this.findSpansAt(from, "code_block").length) return;
1301
1302 this.formatSpan(from, to, source)
1303
1304 // Otherwise we want to change our current formatting state.
1305 } else {
1306 let action:FormatAction = "add"; // By default, we just want our following changes to be bold
1307 let cursor = doc.getCursor("from");
1308
1309 let spans = this.findSpansAt(cursor);
1310 for(let span of spans) {
1311 if(!span.isInline()) continue;
1312 let loc = span.find();
1313 if(!loc) continue;
1314 // If we're at the end of a bold span, we want to stop bolding.
1315 if(samePosition(loc.to, cursor)) action = "remove";
1316 // If we're at the start of a bold span, we want to continue bolding.
1317 if(samePosition(loc.from, cursor)) action = "add";
1318 // Otherwise we're somewhere in the middle, and want to insert some unbolded text.
1319 else action = "split";
1320 }
1321 this.formatting[source.type] = action;
1322 }
1323 this.finalizeLastHistoryEntry();
1324 });
1325 }
1326
1327 formatLine(source:{type:string, level?:number, listData?: {type:"ordered"|"bullet", start?: number}}) {
1328 this.finalizeLastHistoryEntry();

Callers 1

formatMethod · 0.95

Calls 13

findSpansMethod · 0.95
findSpansAtMethod · 0.95
formatSpanMethod · 0.95
adjustToWordBoundaryFunction · 0.90
samePositionFunction · 0.90
getDocMethod · 0.80
operationMethod · 0.80
getCursorMethod · 0.80
getLineMethod · 0.80
somethingSelectedMethod · 0.80
isInlineMethod · 0.80

Tested by

no test coverage detected