diff --git a/assets/editor/main.js b/assets/editor/main.js index 433893a..5076e38 100644 --- a/assets/editor/main.js +++ b/assets/editor/main.js @@ -35,6 +35,10 @@ CM.drawSelection(), CM.indentOnInput(), CM.EditorView.lineWrapping, + // Enable native browser spellcheck on the contenteditable surface + // (CM6 leaves it off by default). autocapitalize helps prose entry + // on the Android/mobile path; CM's DOM observer absorbs corrections. + CM.EditorView.contentAttributes.of({ spellcheck: 'true', autocapitalize: 'sentences' }), CM.markdown({ base: CM.markdownLanguage }), CM.syntaxHighlighting(CM.highlightStyle), CM.closeBrackets(), @@ -257,6 +261,19 @@ } }); + // Keep the editor focused when a toolbar button is tapped. Without this the + // button steals focus on mousedown, which dismisses the mobile soft keyboard + // before the action runs (and view.focus() can't reopen it without a direct + // gesture). preventDefault on mousedown blocks the focus shift; click still + // fires. Scoped to the toolbar so header SAVE/CANCEL are unaffected. Includes + // dropdown toggles, which also must not pull focus off the editor. + var toolbar = document.querySelector('.editor-toolbar'); + if (toolbar) { + toolbar.addEventListener('mousedown', function (e) { + if (e.target.closest('.btn')) e.preventDefault(); + }); + } + document.addEventListener('keydown', function (e) { if (!e.altKey || !e.shiftKey) return; // Shift+digit produces a layout-dependent character in e.key (e.g. "!" @@ -275,7 +292,6 @@ // menus) and on mobile is fixed to the bottom of the viewport. Pin an open // menu to the viewport so it escapes the clip, opening upward when there // isn't room below it (the bottom-toolbar case). - var toolbar = document.querySelector('.editor-toolbar'); function pinMenu(toggle, menu) { if (!menu.classList.contains('is-open')) return; var r = toggle.getBoundingClientRect();