Skip to content

Commit

Permalink
fix(text-editor): make sure trigger characters work on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschmidt committed Nov 20, 2024
1 parent 47b2456 commit 940de41
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,25 @@ export const createTriggerPlugin = (triggerCharacters: TriggerCharacter[]) => {
activeTrigger = null;
};

const handleKeyDown = (view: EditorView, event: any) => {
const { state } = view;

const handleKeyDown = (_: EditorView, event: any) => {
if (event.key === 'Escape') {
stopTrigger();

return true;
}

if (isTrigger(event.key, triggerCharacters) && shouldTrigger(state)) {
activeTrigger = event.key;
return false;
};

const handleInput = (view: EditorView, event: any) => {
const { state } = view;

if (
event.inputType === 'insertText' &&
isTrigger(event.data, triggerCharacters) &&
shouldTrigger(state)
) {
activeTrigger = event.data;
triggerText = '';
triggerPosition = state.selection.$from.pos - triggerText.length;
sendTriggerEvent('triggerStart', view, activeTrigger, triggerText);
Expand Down Expand Up @@ -221,6 +229,9 @@ export const createTriggerPlugin = (triggerCharacters: TriggerCharacter[]) => {
},
props: {
handleKeyDown: handleKeyDown,
handleDOMEvents: {
input: handleInput,
},
},
appendTransaction: appendTransactions,
});
Expand Down

0 comments on commit 940de41

Please sign in to comment.