Skip to content

Commit

Permalink
return early when formatSelection is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Jan 8, 2025
1 parent 4cf9a1a commit 30d5e5d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,12 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
throw new Error('[react-native-live-markdown] Trying to apply format command on empty selection');
}

if (!formatSelection) {
return parseText(parser, target, parsedText, processedMarkdownStyle, cursorPosition);
}

const selectedText = parsedText.slice(contentSelection.current.start, contentSelection.current.end);
const formattedText = formatSelection?.(selectedText, formatCommand) ?? selectedText;
const formattedText = formatSelection(selectedText, formatCommand);

if (selectedText === formattedText) {
return parseText(parser, target, parsedText, processedMarkdownStyle, cursorPosition);
Expand Down

0 comments on commit 30d5e5d

Please sign in to comment.