Skip to content

Commit

Permalink
Fix caret position when deleting forward with no characters selected
Browse files Browse the repository at this point in the history
  • Loading branch information
QichenZhu committed Sep 17, 2024
1 parent 80760df commit 25f99a9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
}

const prevSelection = contentSelection.current ?? {start: 0, end: 0};
const newCursorPosition = Math.max(Math.max(contentSelection.current.end, 0) + (parsedText.length - previousText.length), 0);
const newCursorPosition =
inputType === 'deleteContentForward' && contentSelection.current.start === contentSelection.current.end
? Math.max(contentSelection.current.start, 0) // Don't move the caret when deleting forward with no characters selected
: Math.max(Math.max(contentSelection.current.end, 0) + (parsedText.length - previousText.length), 0);

if (compositionRef.current) {
updateTextColor(divRef.current, parsedText);
Expand Down

0 comments on commit 25f99a9

Please sign in to comment.