arreglar selecciones otra vez (+ estilos)
This commit is contained in:
parent
3c479f91dc
commit
7b4392d1a5
2 changed files with 42 additions and 20 deletions
|
@ -335,27 +335,48 @@ function setupEditor (editorEl) {
|
||||||
const sel = window.getSelection()
|
const sel = window.getSelection()
|
||||||
const range = sel.getRangeAt(0)
|
const range = sel.getRangeAt(0)
|
||||||
|
|
||||||
|
// Borrar todas las selecciones
|
||||||
|
for (const el of contentEl.querySelectorAll(".selected")) {
|
||||||
|
el.classList.remove("selected")
|
||||||
|
}
|
||||||
|
for (const el of contentEl.querySelectorAll(".selected-unactive")) {
|
||||||
|
el.classList.remove("selected-unactive")
|
||||||
|
}
|
||||||
|
|
||||||
for (const [name, type] of Object.entries(typesWithProperties)) {
|
for (const [name, type] of Object.entries(typesWithProperties)) {
|
||||||
|
let i = 0
|
||||||
|
|
||||||
let result
|
let result
|
||||||
try {
|
while (true) {
|
||||||
result = findRecursiveChild(type.checkFn, range.commonAncestorContainer)
|
try {
|
||||||
} catch (err) {
|
result = findRecursiveChild(
|
||||||
// Permission denied or something...
|
el => type.checkFn(el)
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Property_access_denied
|
&& !(el.classList.contains("selected")
|
||||||
console.log("Error raro", err)
|
|| el.classList.contains("selected-unactive")),
|
||||||
break
|
range.commonAncestorContainer
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
// Permission denied or something...
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Property_access_denied
|
||||||
|
console.log("Error raro", err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
if (i === 0) {
|
||||||
|
type.updateInput(result, editorEl)
|
||||||
|
result.classList.add("selected")
|
||||||
|
} else {
|
||||||
|
result.classList.add("selected-unactive")
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (i === 0) {
|
||||||
type.updateInput(result, editorEl)
|
|
||||||
result.classList.add("selected")
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
if (!contentEl.contains(range.commonAncestorContainer)) return
|
|
||||||
type.disableInput(editorEl)
|
type.disableInput(editorEl)
|
||||||
for (const el of contentEl.querySelectorAll(".selected")) {
|
|
||||||
el.classList.remove("selected")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -13,12 +13,13 @@
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.selected {
|
/*.selected, .selected-unactive {
|
||||||
outline: #f206f9 solid medium;
|
|
||||||
outline-offset: 1pt;
|
outline-offset: 1pt;
|
||||||
}
|
}*/
|
||||||
|
.selected { outline: #f206f9 solid medium; }
|
||||||
|
.selected-unactive { outline: gray solid medium; }
|
||||||
|
|
||||||
img, video, iframe {
|
img, video, iframe, audio {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 600px;
|
max-width: 600px;
|
||||||
display: block;
|
display: block;
|
||||||
|
|
Loading…
Reference in a new issue