fix closestVisible

This commit is contained in:
tophf 2020-06-22 19:02:26 +03:00
parent dbb8badc53
commit 62f78c3dd1
2 changed files with 11 additions and 3 deletions

View File

@ -94,6 +94,7 @@ function createSection({
const cm = cmFactory.create(wrapper => {
el.insertBefore(wrapper, $('.code-label', el).nextSibling);
}, {value: originalSection.code});
el.CodeMirror = cm; // used by getAssociatedEditor
const changeListeners = new Set();

View File

@ -154,9 +154,7 @@ function createSectionsEditor({style, onTitleChanged}) {
function closestVisible(nearbyElement) {
const cm =
nearbyElement instanceof CodeMirror ? nearbyElement :
nearbyElement instanceof Node &&
(nearbyElement.closest('#sections > .section') || {}).CodeMirror ||
getLastActivatedEditor();
nearbyElement instanceof Node && getAssociatedEditor(nearbyElement) || getLastActivatedEditor();
if (nearbyElement instanceof Node && cm) {
const {left, top} = nearbyElement.getBoundingClientRect();
const bounds = cm.display.wrapper.getBoundingClientRect();
@ -228,6 +226,15 @@ function createSectionsEditor({style, onTitleChanged}) {
}
}
function getAssociatedEditor(nearbyElement) {
for (let el = nearbyElement; el; el = el.parentElement) {
// added by createSection
if (el.CodeMirror) {
return el.CodeMirror;
}
}
}
function getEditors() {
return sections.filter(s => !s.isRemoved()).map(s => s.cm);
}