Skip to content

Commit

Permalink
Merge pull request #48585 from fedirjh/Fix-selection-48549
Browse files Browse the repository at this point in the history
[Fix] Edit messages by pressing ArrowUp
  • Loading branch information
iwiznia authored Sep 4, 2024
2 parents f040cf2 + e3477a0 commit f890c73
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,7 @@ const CONST = {
HAS_COLON_ONLY_AT_THE_BEGINNING: /^:[^:]+$/,
HAS_AT_MOST_TWO_AT_SIGNS: /^@[^@]*@?[^@]*$/,

EMPTY_COMMENT: /^(\s)*$/,
SPECIAL_CHAR: /[,/?"{}[\]()&^%;`$=#<>!*]/g,

FIRST_SPACE: /.+?(?=\s)/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,24 +481,16 @@ function ComposerWithSuggestions(
}

// Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty and Chronos is not in the participants
const valueLength = valueRef.current.length;
if (
'key' in event &&
event.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey &&
textInputRef.current &&
'selectionStart' in textInputRef.current &&
textInputRef.current?.selectionStart === 0 &&
valueLength === 0 &&
!includeChronos
) {
event.preventDefault();
const isEmptyComment = !valueRef.current || !!valueRef.current.match(CONST.REGEX.EMPTY_COMMENT);
if (webEvent.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && selection.start <= 0 && isEmptyComment && !includeChronos) {
webEvent.preventDefault();
if (lastReportAction) {
const message = Array.isArray(lastReportAction?.message) ? lastReportAction?.message?.at(-1) ?? null : lastReportAction?.message ?? null;
Report.saveReportActionDraft(reportID, lastReportAction, Parser.htmlToMarkdown(message?.html ?? ''));
}
}
},
[shouldUseNarrowLayout, isKeyboardShown, suggestionsRef, includeChronos, handleSendMessage, lastReportAction, reportID],
[shouldUseNarrowLayout, isKeyboardShown, suggestionsRef, selection.start, includeChronos, handleSendMessage, lastReportAction, reportID],
);

const onChangeText = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function ReportActionCompose({

const [isCommentEmpty, setIsCommentEmpty] = useState(() => {
const draftComment = getDraftComment(reportID);
return !draftComment || !!draftComment.match(/^(\s)*$/);
return !draftComment || !!draftComment.match(CONST.REGEX.EMPTY_COMMENT);
});

/**
Expand Down

0 comments on commit f890c73

Please sign in to comment.