Skip to content

Voice recognition handling #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from Expensify/App#40025. Android Chrome doesn't fire the compositionend event, so removing the !BrowserUtils.isMobile condition meant that the component handles text changes as if it's still in composition mode and so this won't run:

newInputUpdate = parseText(parser, divRef.current, parsedText, processedMarkdownStyle, newCursorPosition, true, !inputType, inputType === 'pasteText');

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
Loading