checkpoint

This commit is contained in:
evilchili 2026-07-10 16:21:32 -07:00
parent c1dc49f0b3
commit 95f6ffcf86

View File

@ -386,7 +386,7 @@ export class RibbitEditor extends Ribbit {
return block; return block;
} }
console.log(`Parsing line '${line}'`); //console.log(`Parsing line '${line}'`);
for (const rule of BLOCK_RULES) { for (const rule of BLOCK_RULES) {
const prefixLength = rule.prefixLength(line); const prefixLength = rule.prefixLength(line);
@ -447,6 +447,7 @@ export class RibbitEditor extends Ribbit {
#parseInline(text: string): DocumentFragment { #parseInline(text: string): DocumentFragment {
var t = text; var t = text;
text = disambiguateAsteriskRuns(text); text = disambiguateAsteriskRuns(text);
//console.log(`${t} => ${text}`);
const classes: Record<string, string> = { const classes: Record<string, string> = {
'**': 'md-bold', '**': 'md-bold',
'*': 'md-italic', '*': 'md-italic',
@ -468,7 +469,7 @@ export class RibbitEditor extends Ribbit {
let match: RegExpExecArray | null; let match: RegExpExecArray | null;
while ((match = INLINE_PATTERN.exec(text)) !== null) { while ((match = INLINE_PATTERN.exec(text)) !== null) {
console.log(`DELIM: ${match.groups!.delimiter} CONTENT: ${match.groups!.content} CLOSER: ${match.groups!.closer}`) // console.log(`DELIM: ${match.groups!.delimiter} CONTENT: ${match.groups!.content} CLOSER: ${match.groups!.closer}`)
if (match.index > lastIndex) { if (match.index > lastIndex) {
fragment.appendChild(document.createTextNode(text.slice(lastIndex, match.index))); fragment.appendChild(document.createTextNode(text.slice(lastIndex, match.index)));
} }
@ -481,7 +482,7 @@ export class RibbitEditor extends Ribbit {
fragment.appendChild(document.createTextNode(text.slice(lastIndex))); fragment.appendChild(document.createTextNode(text.slice(lastIndex)));
} }
console.log(`'${t}' => '${text.replace('\u200C', '|')}`, fragment.children); // console.log(`'${t}' => '${text.replace('\u200C', '|')}`, fragment.children);
return fragment; return fragment;
} }
@ -501,6 +502,8 @@ export class RibbitEditor extends Ribbit {
const caretOffset = this.#getCaretOffset(block); const caretOffset = this.#getCaretOffset(block);
const lineText = normalizeLineText(block.textContent!); const lineText = normalizeLineText(block.textContent!);
console.log(`'${block.textContent}' normalized to '${lineText}'`);
const newBlock = this.#buildBlock(lineText); const newBlock = this.#buildBlock(lineText);
block.className = newBlock.className; block.className = newBlock.className;
block.innerHTML = ''; block.innerHTML = '';
@ -515,7 +518,6 @@ export class RibbitEditor extends Ribbit {
lastChild.textContent = lastChild.textContent!.replace(/ $/, '\u00A0'); lastChild.textContent = lastChild.textContent!.replace(/ $/, '\u00A0');
} }
} }
*/
if (lineText.endsWith(' ')) { if (lineText.endsWith(' ')) {
// Find the last text node in the block (may be nested inside spans) // Find the last text node in the block (may be nested inside spans)
const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT); const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT);
@ -527,13 +529,17 @@ export class RibbitEditor extends Ribbit {
if (lastTextNode) { if (lastTextNode) {
lastTextNode.textContent = lastTextNode.textContent!.replace(/ $/, '\u00A0'); lastTextNode.textContent = lastTextNode.textContent!.replace(/ $/, '\u00A0');
} }
console.log(`updating lastTextNode.textContent to '${lastTextNode!.textContent}'`);
} }
*/
const prefixSpan = block.firstElementChild; const prefixSpan = block.firstElementChild;
const prefixLen = (prefixSpan?.classList.contains(DELIM_CLASS) || const prefixLen = (prefixSpan?.classList.contains(DELIM_CLASS) ||
prefixSpan?.classList.contains(LIST_PREFIX_CLASS)) prefixSpan?.classList.contains(LIST_PREFIX_CLASS))
? prefixSpan.textContent!.length : 0; ? prefixSpan.textContent!.length : 0;
console.log(`${block.textContent!}: ${caretOffset} <= ${prefixLen} && ${prefixSpan} ?`);
if (caretOffset <= prefixLen && prefixSpan) { if (caretOffset <= prefixLen && prefixSpan) {
const sel = window.getSelection()!; const sel = window.getSelection()!;
const range = document.createRange(); const range = document.createRange();