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

Improved selection placement when emoji is typed #22827

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
alitoshmatov marked this conversation as resolved.
Show resolved Hide resolved
* @param {String} str1
* @param {String} str2
* @returns {Number}
*/
function getCommonEndingLength(str1, str2) {
MariaHCD marked this conversation as resolved.
Show resolved Hide resolved
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