Improve Editor on mobile
This commit is contained in:
+17
-1
@@ -35,6 +35,10 @@
|
|||||||
CM.drawSelection(),
|
CM.drawSelection(),
|
||||||
CM.indentOnInput(),
|
CM.indentOnInput(),
|
||||||
CM.EditorView.lineWrapping,
|
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.markdown({ base: CM.markdownLanguage }),
|
||||||
CM.syntaxHighlighting(CM.highlightStyle),
|
CM.syntaxHighlighting(CM.highlightStyle),
|
||||||
CM.closeBrackets(),
|
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) {
|
document.addEventListener('keydown', function (e) {
|
||||||
if (!e.altKey || !e.shiftKey) return;
|
if (!e.altKey || !e.shiftKey) return;
|
||||||
// Shift+digit produces a layout-dependent character in e.key (e.g. "!"
|
// 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
|
// 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
|
// menu to the viewport so it escapes the clip, opening upward when there
|
||||||
// isn't room below it (the bottom-toolbar case).
|
// isn't room below it (the bottom-toolbar case).
|
||||||
var toolbar = document.querySelector('.editor-toolbar');
|
|
||||||
function pinMenu(toggle, menu) {
|
function pinMenu(toggle, menu) {
|
||||||
if (!menu.classList.contains('is-open')) return;
|
if (!menu.classList.contains('is-open')) return;
|
||||||
var r = toggle.getBoundingClientRect();
|
var r = toggle.getBoundingClientRect();
|
||||||
|
|||||||
Reference in New Issue
Block a user