Skip to content

Commit

Permalink
Merge branch 'main' into @Skalakid/add-selection-prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Mar 7, 2024
2 parents 002eeaf + 899a12d commit b2e61c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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.16",
"version": "0.1.17",
"description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
12 changes: 12 additions & 0 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
},
ref,
) => {
const compositionRef = useRef<boolean>(false);
const divRef = useRef<HTMLDivElement | null>(null);
const currentlyFocusedField = useRef<HTMLDivElement | null>(null);
const valueLength = value ? value.length : 0;
Expand Down Expand Up @@ -260,6 +261,12 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
return;
}

if (compositionRef.current) {
updateTextColor(divRef.current, e.target.innerText);
compositionRef.current = false;
return;
}

let text = '';
const nativeEvent = e.nativeEvent as MarkdownNativeEvent;
switch (nativeEvent.inputType) {
Expand Down Expand Up @@ -449,6 +456,10 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
[onClick],
);

const startComposition = useCallback(() => {
compositionRef.current = true;
}, []);

const setRef = (currentRef: HTMLDivElement | null) => {
const r = currentRef;
if (r) {
Expand Down Expand Up @@ -557,6 +568,7 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
autoCapitalize={autoCapitalize}
className={className}
onKeyDown={handleKeyPress}
onCompositionStart={startComposition}
onKeyUp={updateSelection}
onInput={handleOnChangeText}
onClick={handleClick}
Expand Down

0 comments on commit b2e61c5

Please sign in to comment.