arreglar selecciones otra vez (+ estilos)

This commit is contained in:
void 2020-11-09 15:08:47 -03:00
parent 3c479f91dc
commit 7b4392d1a5
2 changed files with 42 additions and 20 deletions

View file

@ -335,10 +335,26 @@ 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
while (true) {
try { try {
result = findRecursiveChild(type.checkFn, range.commonAncestorContainer) result = findRecursiveChild(
el => type.checkFn(el)
&& !(el.classList.contains("selected")
|| el.classList.contains("selected-unactive")),
range.commonAncestorContainer
)
} catch (err) { } catch (err) {
// Permission denied or something... // Permission denied or something...
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Property_access_denied // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Property_access_denied
@ -347,15 +363,20 @@ function setupEditor (editorEl) {
} }
if (result) { if (result) {
if (i === 0) {
type.updateInput(result, editorEl) type.updateInput(result, editorEl)
result.classList.add("selected") result.classList.add("selected")
break
} else { } else {
if (!contentEl.contains(range.commonAncestorContainer)) return result.classList.add("selected-unactive")
type.disableInput(editorEl)
for (const el of contentEl.querySelectorAll(".selected")) {
el.classList.remove("selected")
} }
i++
} else {
break
}
}
if (i === 0) {
type.disableInput(editorEl)
} }
} }
}) })

View file

@ -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;