Skip to content

Commit

Permalink
fix: type markdown native event
Browse files Browse the repository at this point in the history
  • Loading branch information
nkdengineer committed Oct 31, 2024
1 parent 4e4f13d commit 7ff4203
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface MarkdownTextInputProps extends TextInputProps, InlineImagesInputProps
}

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

type MarkdownTextInput = TextInput & React.Component<MarkdownTextInputProps>;
Expand Down Expand Up @@ -316,7 +316,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 7ff4203

Please sign in to comment.