Skip to content

Commit

Permalink
Added getCommonEndingLength and implemented it
Browse files Browse the repository at this point in the history
  • Loading branch information
alitoshmatov committed Jul 13, 2023
1 parent 5a823e2 commit 31096c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/libs/ComposerUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,18 @@ function canSkipTriggerHotkeys(isSmallScreenWidth, isKeyboardShown) {
return (isSmallScreenWidth && DeviceCapabilities.canUseTouchScreen()) || isKeyboardShown;
}

export {getNumberOfLines, updateNumberOfLines, insertText, canSkipTriggerHotkeys};
/**
* Find length of common ending of two strings
* @param {String} str1
* @param {String} str2
* @returns {Number}
*/
function getCommonEndingLength(str1, str2) {
let i = 0;
while (str1[str1.length - 1 - i] === str2[str2.length - 1 - i]) {
i++;
}
return i;
}

export {getNumberOfLines, updateNumberOfLines, insertText, canSkipTriggerHotkeys, getCommonEndingLength};
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.getCommonEndingLength(comment, newComment);
newState.selection = {
start: newComment.length - remainder,
end: newComment.length - remainder,
Expand Down

0 comments on commit 31096c5

Please sign in to comment.