Skip to content

Commit

Permalink
Merge pull request #47596 from bernhardoj/fix/46095-composer-selectio…
Browse files Browse the repository at this point in the history
…n-is-at-start

Fix composer selection is at start after when copying link to a message
  • Loading branch information
MariaHCD committed Aug 20, 2024
2 parents eb5964a + bc51410 commit 72c8cf7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/components/Composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as Browser from '@libs/Browser';
import updateIsFullComposerAvailable from '@libs/ComposerUtils/updateIsFullComposerAvailable';
import * as EmojiUtils from '@libs/EmojiUtils';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import focusComposerWithDelay from '@libs/focusComposerWithDelay';
import isEnterWhileComposition from '@libs/KeyboardShortcut/isEnterWhileComposition';
import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -413,7 +414,7 @@ function Composer(
return;
}

textInput.current.focus();
focusComposerWithDelay(textInput.current)(true);
});

props.onFocus?.(e);
Expand Down
5 changes: 4 additions & 1 deletion src/components/Modal/BaseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ function BaseModal(
avoidKeyboard={avoidKeyboard}
customBackdrop={shouldUseCustomBackdrop ? <Overlay onPress={handleBackdropPress} /> : undefined}
>
<ModalContent onDismiss={handleDismissModal}>
<ModalContent
onModalWillShow={saveFocusState}
onDismiss={handleDismissModal}
>
<PortalHost name="modal" />
<FocusTrapForModal
active={isVisible}
Expand Down
12 changes: 9 additions & 3 deletions src/components/Modal/ModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ type ModalContentProps = {
* such as closing the attachment modal through the browser's back button.
* */
onDismiss: () => void;

/** Callback method fired after modal content is mounted. */
onModalWillShow: () => void;
};

function ModalContent({children, onDismiss = () => {}}: ModalContentProps) {
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
React.useEffect(() => () => onDismiss?.(), []);
function ModalContent({children, onDismiss = () => {}, onModalWillShow = () => {}}: ModalContentProps) {
React.useEffect(() => {
onModalWillShow();
return onDismiss;
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);
return children;
}
ModalContent.displayName = 'ModalContent';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function ComposerWithSuggestions(
const valueRef = useRef(value);
valueRef.current = value;

const [selection, setSelection] = useState<TextSelection>(() => ({start: 0, end: 0, positionX: 0, positionY: 0}));
const [selection, setSelection] = useState<TextSelection>(() => ({start: value.length, end: value.length, positionX: 0, positionY: 0}));

const [composerHeight, setComposerHeight] = useState(0);

Expand Down Expand Up @@ -562,7 +562,7 @@ function ComposerWithSuggestions(
return;
}

focus(false);
focus(true);
}, true);
}, [focus, isFocused]);

Expand Down

0 comments on commit 72c8cf7

Please sign in to comment.