Skip to content

Commit

Permalink
Fix caret position in web when deleting forward with no characters se…
Browse files Browse the repository at this point in the history
…lected (#496)
  • Loading branch information
QichenZhu authored Sep 17, 2024
1 parent 3517225 commit 35ad3b4
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 35ad3b4

Please sign in to comment.