Skip to content

Commit

Permalink
Merge branch 'main' into @tomekzaw/worklets
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed Nov 5, 2024
2 parents 62bc84e + 8096a9a commit ff832bb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expensify/react-native-live-markdown",
"version": "0.1.178",
"version": "0.1.180",
"description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
4 changes: 2 additions & 2 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface MarkdownTextInputProps extends TextInputProps, InlineImagesInputProps
}

interface MarkdownNativeEvent extends Event {
inputType: string;
inputType?: string;
}

type MarkdownTextInput = TextInput & React.Component<MarkdownTextInputProps>;
Expand Down Expand Up @@ -324,7 +324,7 @@ const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputP
updateTextColor(divRef.current, e.target.textContent ?? '');
const previousText = divRef.current.value;
let parsedText = normalizeValue(
inputType === 'pasteText' ? pasteContent.current || '' : parseInnerHTMLToText(e.target as MarkdownTextInputElement, inputType, contentSelection.current.start),
inputType === 'pasteText' ? pasteContent.current || '' : parseInnerHTMLToText(e.target as MarkdownTextInputElement, contentSelection.current.start, inputType),
);

if (pasteContent.current) {
Expand Down
4 changes: 2 additions & 2 deletions src/web/utils/inputUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function normalizeValue(value: string) {
}

// Parses the HTML structure of a MarkdownTextInputElement to a plain text string. Used for getting the correct value of the input element.
function parseInnerHTMLToText(target: MarkdownTextInputElement, inputType: string, cursorPosition: number): string {
function parseInnerHTMLToText(target: MarkdownTextInputElement, cursorPosition: number, inputType?: string): string {
// Returns the parent of a given node that is higher in the hierarchy and is of a different type than 'text', 'br' or 'line'
function getTopParentNode(node: ChildNode) {
let currentParentNode = node.parentNode;
Expand Down Expand Up @@ -104,7 +104,7 @@ function parseInnerHTMLToText(target: MarkdownTextInputElement, inputType: strin
text = text.replaceAll('\r\n', '\n');

// Force letter removal if the input value haven't changed but input type is 'delete'
if (text === target.value && inputType.includes('delete')) {
if (text === target.value && inputType?.includes('delete')) {
text = text.slice(0, cursorPosition - 1) + text.slice(cursorPosition);
}
return text;
Expand Down

0 comments on commit ff832bb

Please sign in to comment.