Skip to content

Commit b09a961

Browse files
committed
Review changes
1 parent b79fd51 commit b09a961

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

src/libs/focusComposerWithDelay/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ function focusComposerWithDelay(textInput: InputType | null): FocusComposerWithD
1010
/**
1111
* Focus the text input
1212
* @param [shouldDelay] Impose delay before focusing the text input
13-
* @param [forceSetSelection] Force selection range of text input
13+
* @param [forcedSelectionRange] Force selection range of text input
1414
*/
15-
return (shouldDelay = false, forceSetSelection = undefined) => {
15+
return (shouldDelay = false, forcedSelectionRange = undefined) => {
1616
// There could be other animations running while we trigger manual focus.
1717
// This prevents focus from making those animations janky.
1818
if (!textInput || EmojiPickerAction.isEmojiPickerVisible()) {
@@ -21,8 +21,8 @@ function focusComposerWithDelay(textInput: InputType | null): FocusComposerWithD
2121

2222
if (!shouldDelay) {
2323
textInput.focus();
24-
if (forceSetSelection) {
25-
setTextInputSelection(textInput, forceSetSelection);
24+
if (forcedSelectionRange) {
25+
setTextInputSelection(textInput, forcedSelectionRange);
2626
}
2727
return;
2828
}
@@ -31,8 +31,8 @@ function focusComposerWithDelay(textInput: InputType | null): FocusComposerWithD
3131
return;
3232
}
3333
textInput.focus();
34-
if (forceSetSelection) {
35-
setTextInputSelection(textInput, forceSetSelection);
34+
if (forcedSelectionRange) {
35+
setTextInputSelection(textInput, forcedSelectionRange);
3636
}
3737
});
3838
};

src/libs/focusComposerWithDelay/setTextInputSelection.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import type {InputType, Selection} from './types';
44

55
const setSelectionRange = shouldSetSelectionRange();
66

7-
const setTextInputSelection = (textInput: InputType, forceSetSelection: Selection) => {
7+
const setTextInputSelection = (textInput: InputType, forcedSelectionRange: Selection) => {
88
if (setSelectionRange) {
9-
(textInput as HTMLTextAreaElement).setSelectionRange(forceSetSelection.start, forceSetSelection.end);
9+
(textInput as HTMLTextAreaElement).setSelectionRange(forcedSelectionRange.start, forcedSelectionRange.end);
1010
} else {
11-
(textInput as TextInput).setSelection(forceSetSelection.start, forceSetSelection.end);
11+
(textInput as TextInput).setSelection(forcedSelectionRange.start, forcedSelectionRange.end);
1212
}
1313
};
1414

src/libs/focusComposerWithDelay/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type Selection = {
55
end: number;
66
};
77

8-
type FocusComposerWithDelay = (shouldDelay?: boolean, forceSetSelection?: Selection) => void;
8+
type FocusComposerWithDelay = (shouldDelay?: boolean, forcedSelectionRange?: Selection) => void;
99

1010
type InputType = TextInput | HTMLTextAreaElement;
1111

src/pages/home/report/ReportActionItemMessageEdit.tsx

+5-8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const emojiButtonID = 'emojiButton';
6969
const messageEditInput = 'messageEditInput';
7070

7171
const isMobileSafari = Browser.isMobileSafari();
72+
const shouldUseForcedSelectionRange = shouldUseEmojiPickerSelection();
7273

7374
function ReportActionItemMessageEdit(
7475
{action, draftMessage, reportID, index, shouldDisableEmojiPicker = false, preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE}: ReportActionItemMessageEditProps,
@@ -330,7 +331,6 @@ function ReportActionItemMessageEdit(
330331
deleteDraft();
331332
}, [action, debouncedSaveDraft, deleteDraft, draft, reportID]);
332333

333-
const shouldUseEmojiPickerSelectionRef = shouldUseEmojiPickerSelection();
334334
/**
335335
* @param emoji
336336
*/
@@ -341,9 +341,9 @@ function ReportActionItemMessageEdit(
341341
};
342342
setSelection(newSelection);
343343

344-
if (shouldUseEmojiPickerSelectionRef) {
345-
// immediately set the selection again on android and Chrome mobile after focusing the
346-
// input which seems to change the cursor position for a brief moment
344+
if (shouldUseForcedSelectionRange) {
345+
// On Android and Chrome mobile, focusing the input sets the cursor position back to the start.
346+
// To fix this, immediately set the selection again after focusing the input.
347347
emojiPickerSelectionRef.current = newSelection;
348348
}
349349
updateDraft(ComposerUtils.insertText(draft, selection, `${emoji} `));
@@ -460,10 +460,7 @@ function ReportActionItemMessageEdit(
460460
<EmojiPickerButton
461461
isDisabled={shouldDisableEmojiPicker}
462462
onModalHide={() => {
463-
const emojiPickerSelection = emojiPickerSelectionRef.current ? {...emojiPickerSelectionRef.current} : undefined;
464-
emojiPickerSelectionRef.current = undefined;
465-
466-
focus(true, emojiPickerSelection);
463+
focus(true, emojiPickerSelectionRef.current ? {...emojiPickerSelectionRef.current} : undefined);
467464
}}
468465
onEmojiSelected={addEmojiToTextBox}
469466
id={emojiButtonID}

0 commit comments

Comments
 (0)