Skip to content
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

fix: cursor issue starting on left of text #25528

Merged
merged 15 commits into from
Sep 12, 2023
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
34 changes: 25 additions & 9 deletions src/pages/home/report/ReportActionItemMessageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import useReportScrollManager from '../../../hooks/useReportScrollManager';
import * as EmojiPickerAction from '../../../libs/actions/EmojiPickerAction';
import focusWithDelay from '../../../libs/focusWithDelay';
import ONYXKEYS from '../../../ONYXKEYS';
import * as Browser from '../../../libs/Browser';

const propTypes = {
/** All the data of the action */
Expand Down Expand Up @@ -88,22 +89,35 @@ const cancelButtonID = 'cancelButton';
const emojiButtonID = 'emojiButton';
const messageEditInput = 'messageEditInput';

const isMobileSafari = Browser.isMobileSafari();

function ReportActionItemMessageEdit(props) {
const reportScrollManager = useReportScrollManager();
const {translate} = useLocalize();
const {isKeyboardShown} = useKeyboardState();
const {isSmallScreenWidth} = useWindowDimensions();

const [draft, setDraft] = useState(() => {
const getInitialDraft = () => {
if (props.draftMessage === props.action.message[0].html) {
// We only convert the report action message to markdown if the draft message is unchanged.
const parser = new ExpensiMark();
return parser.htmlToMarkdown(props.draftMessage).trim();
}
// We need to decode saved draft message because it's escaped before saving.
return Str.htmlDecode(props.draftMessage);
});
const [selection, setSelection] = useState({start: 0, end: 0});
};

const getInitialSelection = () => {
if (isMobileSafari) {
return {start: 0, end: 0};
}

const length = getInitialDraft().length;
return {start: length, end: length};
};

const [draft, setDraft] = useState(() => getInitialDraft());
const [selection, setSelection] = useState(getInitialSelection());
const [isFocused, setIsFocused] = useState(false);
const [hasExceededMaxCommentLength, setHasExceededMaxCommentLength] = useState(false);

Expand All @@ -120,13 +134,15 @@ function ReportActionItemMessageEdit(props) {
// For mobile Safari, updating the selection prop on an unfocused input will cause it to automatically gain focus
// and subsequent programmatic focus shifts (e.g., modal focus trap) to show the blue frame (:focus-visible style),
// so we need to ensure that it is only updated after focus.
setDraft((prevDraft) => {
setSelection({
start: prevDraft.length,
end: prevDraft.length,
if (isMobileSafari) {
setDraft((prevDraft) => {
setSelection({
start: prevDraft.length,
end: prevDraft.length,
});
return prevDraft;
});
return prevDraft;
});
}
jeet-dhandha marked this conversation as resolved.
Show resolved Hide resolved

return () => {
// Skip if this is not the focused message so the other edit composer stays focused.
Expand Down
Loading