WIP: arreglar marcado de cosas entre varios elementos
This commit is contained in:
parent
52f9fe5b22
commit
6489680c57
1 changed files with 12 additions and 9 deletions
|
@ -52,10 +52,14 @@ export function setupButtons (editor: Editor): void {
|
|||
const range = safeGetRangeAt(sel)
|
||||
if (!range) return
|
||||
|
||||
if (!(range.commonAncestorContainer instanceof Element))
|
||||
throw new Error(':/')
|
||||
let parentEl = range.commonAncestorContainer
|
||||
while (!(parentEl instanceof Element)) {
|
||||
if (!parentEl.parentElement) return
|
||||
parentEl = parentEl.parentElement
|
||||
}
|
||||
|
||||
const existingMarks = recursiveFilterSelection(
|
||||
range.commonAncestorContainer,
|
||||
parentEl,
|
||||
sel,
|
||||
type.selector,
|
||||
)
|
||||
|
@ -68,14 +72,13 @@ export function setupButtons (editor: Editor): void {
|
|||
moveChildren(mark, mark.parentElement, mark)
|
||||
mark.parentElement.removeChild(mark)
|
||||
} else {
|
||||
const tagEl = type.create()
|
||||
|
||||
try {
|
||||
range.surroundContents(tagEl)
|
||||
} catch (error) {
|
||||
if (range.commonAncestorContainer === editor.contentEl)
|
||||
// TODO: mostrar error
|
||||
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.selectNode(tagEl)
|
||||
|
|
Loading…
Reference in a new issue