Skip to content

Commit

Permalink
Fix app crashing when entering the emoji (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid authored Mar 29, 2024
1 parent 7c9d9b0 commit 149f09a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
markdownHTMLInput.selectionEnd = end;
}, []);

const updateSelection = useCallback((e: SyntheticEvent<HTMLDivElement> | null = null) => {
const updateSelection = useCallback((e: SyntheticEvent<HTMLDivElement> | null = null, predefinedSelection: Selection | null = null) => {
if (!divRef.current) {
return;
}
const newSelection = CursorUtils.getCurrentCursorPosition(divRef.current);
const newSelection = predefinedSelection || CursorUtils.getCurrentCursorPosition(divRef.current);

if (newSelection && (!contentSelection.current || contentSelection.current.start !== newSelection.start || contentSelection.current.end !== newSelection.end)) {
updateRefSelectionVariables(newSelection);
Expand Down Expand Up @@ -529,7 +529,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
return;
}
CursorUtils.setCursorPosition(divRef.current, selection.start, selection.end);
updateSelection();
updateSelection(null, {start: selection.start, end: selection.end || selection.start});
}, [selection]);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/web/cursorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function scrollCursorIntoView(target: HTMLInputElement) {
}

const selection = window.getSelection();
if (!selection) {
if (!selection || (selection && selection.rangeCount === 0)) {
return;
}

Expand Down

0 comments on commit 149f09a

Please sign in to comment.