Skip to content

Commit

Permalink
Voice recognition handling (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszGrajdek authored Aug 14, 2024
1 parent 4268878 commit 3a97f41
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {StyleSheet} from 'react-native';
import * as ParseUtils from './web/parserUtils';
import * as CursorUtils from './web/cursorUtils';
import * as StyleUtils from './styleUtils';
import * as BrowserUtils from './web/browserUtils';
import type * as MarkdownTextInputDecoratorViewNativeComponent from './MarkdownTextInputDecoratorViewNativeComponent';
import './web/MarkdownTextInput.css';
import InputHistory from './web/InputHistory';
Expand Down Expand Up @@ -355,9 +354,8 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
const prevSelection = contentSelection.current ?? {start: 0, end: 0};
const prevTextLength = CursorUtils.getPrevTextLength() ?? 0;
const changedText = e.target.innerText;
if (compositionRef.current && !BrowserUtils.isMobile) {
if (compositionRef.current) {
updateTextColor(divRef.current, changedText);
compositionRef.current = false;
return;
}

Expand Down Expand Up @@ -582,6 +580,14 @@ const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
compositionRef.current = true;
}, []);

const endComposition = useCallback(
(e) => {
compositionRef.current = false;
handleOnChangeText(e);
},
[handleOnChangeText],
);

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

0 comments on commit 3a97f41

Please sign in to comment.