(context: Node)
| 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 |
| 1364 | let text = ""; |
| 1365 | let formatted = false; |
| 1366 | function 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) { |
no test coverage detected