Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 18 additions & 1 deletion src/libs/ComposerUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,21 @@ function canSkipTriggerHotkeys(isSmallScreenWidth, isKeyboardShown) {
return (isSmallScreenWidth && DeviceCapabilities.canUseTouchScreen()) || isKeyboardShown;
}

export {getNumberOfLines, updateNumberOfLines, insertText, canSkipTriggerHotkeys};
/**
* Returns the length of the common suffix between two input strings.
* The common suffix is the number of characters shared by both strings
* at the end (suffix) until a mismatch is encountered.
*
* @param {string} str1
* @param {string} str2
* @returns {number} The length of the common suffix between the strings.
*/
function getCommonSuffixLength(str1, str2) {
let i = 0;
while (str1[str1.length - 1 - i] === str2[str2.length - 1 - i]) {
i++;
}
return i;
}

export {getNumberOfLines, updateNumberOfLines, insertText, canSkipTriggerHotkeys, getCommonSuffixLength};
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,13 @@ class ReportActionCompose extends React.Component {
this.debouncedUpdateFrequentlyUsedEmojis();
}

this.setState((prevState) => {
this.setState(() => {
const newState = {
isCommentEmpty: !!newComment.match(/^(\s)*$/),
value: newComment,
};
if (comment !== newComment) {
const remainder = prevState.value.slice(prevState.selection.end).length;
const remainder = ComposerUtils.getCommonSuffixLength(comment, newComment);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coming from #27195, this has caused a small inconsistency between the composer when sending a message and when editing it.
We should have used the same calculation for the remainder (getCommonSuffixLength) in ReportActionItemMessageEdit too.

newState.selection = {
start: newComment.length - remainder,
end: newComment.length - remainder,
Expand Down