WIP: arreglar marcado de cosas entre varios elementos

This commit is contained in:
void 2021-02-12 19:10:55 +00:00
parent 52f9fe5b22
commit 6489680c57

View file

@ -52,10 +52,14 @@ export function setupButtons (editor: Editor): void {
const range = safeGetRangeAt(sel) const range = safeGetRangeAt(sel)
if (!range) return if (!range) return
if (!(range.commonAncestorContainer instanceof Element)) let parentEl = range.commonAncestorContainer
throw new Error(':/') while (!(parentEl instanceof Element)) {
if (!parentEl.parentElement) return
parentEl = parentEl.parentElement
}
const existingMarks = recursiveFilterSelection( const existingMarks = recursiveFilterSelection(
range.commonAncestorContainer, parentEl,
sel, sel,
type.selector, type.selector,
) )
@ -68,14 +72,13 @@ export function setupButtons (editor: Editor): void {
moveChildren(mark, mark.parentElement, mark) moveChildren(mark, mark.parentElement, mark)
mark.parentElement.removeChild(mark) mark.parentElement.removeChild(mark)
} else { } else {
const tagEl = type.create() if (range.commonAncestorContainer === editor.contentEl)
try {
range.surroundContents(tagEl)
} catch (error) {
// TODO: mostrar error // TODO: mostrar error
return console.error("No puedo marcar cosas a través de distintos bloques!") return console.error("No puedo marcar cosas a través de distintos bloques!")
}
const tagEl = type.create()
tagEl.appendChild(range.extractContents())
range.insertNode(tagEl) range.insertNode(tagEl)
range.selectNode(tagEl) range.selectNode(tagEl)