diff --git a/src/dom.ts b/src/dom.ts index 3eda765..afdd52e 100644 --- a/src/dom.ts +++ b/src/dom.ts @@ -283,6 +283,7 @@ export function textRange(node: Text, from: number, to = from) { } export function dispatchKey(elt: HTMLElement, name: string, code: number): boolean { + console.log("dispatch", name) let options = {key: name, code: name, keyCode: code, which: code, cancelable: true} let down = new KeyboardEvent("keydown", options) ;(down as any).synthetic = true diff --git a/src/domchange.ts b/src/domchange.ts index 5ce7ca3..1aa80bf 100644 --- a/src/domchange.ts +++ b/src/domchange.ts @@ -116,7 +116,7 @@ export function applyDOMChange(view: EditorView, domChange: DOMChange): boolean } if (change) { - if (browser.ios && view.inputState.flushIOSKey()) return true + if (browser.ios && view.inputState.flushIOSKey(change)) return true // Android browsers don't fire reasonable key events for enter, // backspace, or delete. So this detects changes that look like // they're caused by those keys, and reinterprets them as key diff --git a/src/input.ts b/src/input.ts index c30d19c..aa3f2f3 100644 --- a/src/input.ts +++ b/src/input.ts @@ -1,4 +1,4 @@ -import {EditorSelection, EditorState, SelectionRange, RangeSet, Annotation} from "@codemirror/state" +import {EditorSelection, EditorState, SelectionRange, RangeSet, Annotation, Text} from "@codemirror/state" import {EditorView} from "./editorview" import {ContentView} from "./contentview" import {LineView} from "./blockview" @@ -142,9 +142,11 @@ export class InputState { return false } - flushIOSKey() { + flushIOSKey(change?: {from: number, to: number, insert: Text}) { let key = this.pendingIOSKey if (!key) return false + // This looks like an autocorrection before Enter + if (key.key == "Enter" && change && change.from < change.to && /^\S+$/.test(change.insert.toString())) return false this.pendingIOSKey = undefined return dispatchKey(this.view.contentDOM, key.key, key.keyCode) }