Skip to content

Commit

Permalink
feat: update backspace handle logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mamadoudicko committed Aug 28, 2023
1 parent 182751f commit 0ba53c9
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,21 @@ export const useMentionInput = ({
setEditorState(EditorState.createEmpty());
}, [setEditorState]);

// eslint-disable-next-line complexity
const keyBindingFn = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (mentionTriggers.includes(e.key as MentionTriggerType)) {
setOpen(true);

return getDefaultKeyBinding(e);
}

if (
(e.key === "Backspace" || e.key === "Delete") &&
getEditorText(editorState) === ""
) {
return "backspace";
}

if (e.key === "Enter" && !e.shiftKey) {
onSubmit();

Expand Down

0 comments on commit 0ba53c9

Please sign in to comment.