Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/modules/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ export function input(editor: Editor) {
}
}

function setCompositionEnabled(enabled = true) {
if (enabled) {
editor.root.addEventListener('compositionstart', onCompositionStart);
editor.root.addEventListener('compositionend', onCompositionEnd);
} else {
editor.root.removeEventListener('compositionstart', onCompositionStart);
editor.root.removeEventListener('compositionend', onCompositionEnd);
}
}

// Browsers have had issues in the past with mutation observers firing consistently, so use the observer with the input
// event as fallback
function onInput() {
Expand Down Expand Up @@ -175,19 +185,12 @@ export function input(editor: Editor) {
}

return {
allowComposition(value = true) {
if (value) {
editor.root.addEventListener('compositionstart', onCompositionStart);
editor.root.addEventListener('compositionend', onCompositionEnd);
} else {
editor.root.removeEventListener('compositionstart', onCompositionStart);
editor.root.removeEventListener('compositionend', onCompositionEnd);
}
},
allowComposition: setCompositionEnabled,
init() {
editor.root.addEventListener('input', onInput);
editor.on('rendering', onRendering);
editor.on('render', onRender);
setCompositionEnabled(true)
if (isAndroid) {
editor.root.addEventListener('beforeinput', onBeforeInput); // needed for Gboard fix
}
Expand Down