Commit fd2dc360 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt Committed by Robert

fix: sticky toolbar disappears whenever it’s used. refs #597

as the toolbar is not directly a part of the codemirror editor
editor.codemirror.hasFocus() returns false when one of the toolbar
buttons is clicked. the new check checks both the editor itself and if
the container element contains the currently focused element in the
page. setTimeout is necessary to avoid false results for the contains
call because at the time when our callback is executed activeElement
might refer to the body element as the browser is in-between states.
reschedulung our handler code in the event code will ensure that
document.activeElement get’s the correct element.
parent d26d2829
......@@ -77,7 +77,10 @@ function editor (CodeMirror, SimpleMDE, el, opts) {
// create focusListener to move the toolbar into the current scrollPosition
// whenever the editor is focused
const focusListener = on(codemirrorEvents, ['focus', 'blur'], () => {
containerEl.classList.toggle('editor-container-active', editor.codemirror.hasFocus())
window.setTimeout(() => {
editor.codemirror.hasFocus() || containerEl.contains(document.activeElement))
}, 0)
// prevent users from accidentally leaving the page when
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment