MCPcopy Create free account
hub / github.com/MathMan05/Fermi / crawlForText

Function crawlForText

src/webpage/markdown.ts:1355–1389  ·  view source on GitHub ↗
(context: Node)

Source from the content-addressed store, hash-verified

1353 static replace(base: HTMLElement, newelm: HTMLElement) {
1354 const basechildren = base.children;
1355 const newchildren = newelm.children;
1356 for (const thing of Array.from(newchildren)) {
1357 base.append(thing);
1358 }
1359 }
1360 */
1361}
1362
1363//solution from https://stackoverflow.com/questions/4576694/saving-and-restoring-caret-position-for-contenteditable-div
1364let text = "";
1365let formatted = false;
1366function saveCaretPosition(
1367 context: HTMLElement,
1368 offset = 0,
1369 txtLengthFunc = MarkDown.gatherBoxText.bind(MarkDown),
1370 computedLength: void | number = undefined,
1371) {
1372 const selection = window.getSelection() as Selection;
1373 if (!selection) return;
1374 try {
1375 const range = selection.getRangeAt(0);
1376
1377 let base = selection.anchorNode as Node;
1378 range.setStart(base, 0);
1379 let baseString: string;
1380 let i = 0;
1381 const index = selection.focusOffset;
1382
1383 for (const thing of Array.from(base.childNodes)) {
1384 if (i === index) {
1385 base = thing;
1386 break;
1387 }
1388 i++;
1389 }
1390 const prev = base.previousSibling;
1391 let len = 0;
1392 if ((!prev || prev instanceof HTMLBRElement) && base instanceof HTMLBRElement) {

Callers 1

saveCaretPositionFunction · 0.85

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected