Skip to content

Commit

Permalink
Fix crashes and cursor positioning in E/App
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Jul 1, 2024
1 parent 1f1fefd commit ff41dd7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
const setEventProps = useCallback((e: NativeSyntheticEvent<any>) => {
if (divRef.current) {
const text = divRef.current.value;
if (e.target) {
// TODO: change the logic here so every event have value property
(e.target as unknown as HTMLInputElement).value = text;
}
if (e.nativeEvent && e.nativeEvent.text) {
e.nativeEvent.text = text;
}
Expand Down Expand Up @@ -526,7 +530,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
parseText(divRef.current, value, processedMarkdownStyle);
updateTextColor(divRef.current, value);
},
[multiline, processedMarkdownStyle],
[multiline, processedMarkdownStyle, value],
);

useClientEffect(
Expand Down
2 changes: 1 addition & 1 deletion src/web/utils/cursorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {findHTMLElementInTree, getTreeNodeByIndex} from './treeUtils';

function setCursorPosition(target: MarkdownTextInputElement, start: number, end: number | null = null) {
// We don't want to move the cursor if the target is not focused
if (target !== document.activeElement || start < 0 || (end && end < 0)) {
if (!target.tree || target !== document.activeElement || start < 0 || (end && end < 0)) {
return;
}

Expand Down

0 comments on commit ff41dd7

Please sign in to comment.