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

Create a common function to insert an emoji into a text #17346

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f3abb8a
create a common function to insert an emoji into a text
bernhardoj Apr 11, 2023
9754214
add return type
bernhardoj Apr 12, 2023
12160a4
fix lint
bernhardoj Apr 12, 2023
be7f2a5
Merge branch 'main' into fix/15951-remove-space-on-add-emoji-from-picker
bernhardoj Apr 13, 2023
aeb0286
move the function to another util file
bernhardoj Apr 14, 2023
28b6f81
Merge branch 'main' into fix/15951-remove-space-on-add-emoji-from-picker
bernhardoj Apr 14, 2023
3ef5fa6
Merge branch 'main' into fix/15951-remove-space-on-add-emoji-from-picker
bernhardoj Apr 14, 2023
114d424
Revert "move the function to another util file"
bernhardoj Apr 14, 2023
61c8bdf
move the function to another util file
bernhardoj Apr 14, 2023
c24368b
fix lint
bernhardoj Apr 14, 2023
1403e4b
Merge branch 'main' into fix/15951-remove-space-on-add-emoji-from-picker
bernhardoj Apr 17, 2023
dc19e14
move to another util file
bernhardoj Apr 17, 2023
f9c3222
fix lint
bernhardoj Apr 17, 2023
980318e
Merge branch 'main' into fix/15951-remove-space-on-add-emoji-from-picker
bernhardoj Apr 17, 2023
317f581
Merge branch 'main' into fix/15951-remove-space-on-add-emoji-from-picker
bernhardoj Apr 18, 2023
530ed07
reorganize common and platform specific file
bernhardoj Apr 19, 2023
e549f83
simplify code
bernhardoj Apr 19, 2023
a50526b
Merge branch 'main' into fix/15951-remove-space-on-add-emoji-from-picker
bernhardoj Apr 19, 2023
307c828
Merge branch 'main' into fix/15951-remove-space-on-add-emoji-from-picker
bernhardoj Apr 20, 2023
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
12 changes: 12 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,17 @@ function canLeaveRoom(report, isPolicyMember) {
return true;
}

/**
* Replace substring between selection with a text.
* @param {String} text
* @param {Object} selection
* @param {String} textToInsert
* @returns {String}
*/
function insertText(text, selection, textToInsert) {
return text.slice(0, selection.start) + textToInsert + text.slice(selection.end, text.length);
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -1775,4 +1786,5 @@ export {
getSmallSizeAvatar,
getMoneyRequestOptions,
canRequestMoney,
insertText,
};
9 changes: 3 additions & 6 deletions src/pages/home/report/ReportActionCompose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,13 @@ class ReportActionCompose extends React.Component {
* @param {String} text
*/
replaceSelectionWithInput(text) {
const newComment = this.comment.slice(0, this.state.selection.start)
+ text
+ this.comment.slice(this.state.selection.end, this.comment.length);
this.setState(prevState => ({
selection: {
start: prevState.selection.start + text.length,
end: prevState.selection.start + text.length,
},
}), this.updateComment(newComment));
}));
this.updateComment(ReportUtils.insertText(this.comment, this.state.selection, text));
}

/**
Expand All @@ -519,8 +517,7 @@ class ReportActionCompose extends React.Component {
* @param {String} emoji
*/
addEmojiToTextBox(emoji) {
bernhardoj marked this conversation as resolved.
Show resolved Hide resolved
const emojiWithSpace = `${emoji} `;
this.replaceSelectionWithInput(emojiWithSpace);
this.replaceSelectionWithInput(emoji);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/pages/home/report/ReportActionItemMessageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,13 @@ class ReportActionItemMessageEdit extends React.Component {
* @param {String} emoji
*/
addEmojiToTextBox(emoji) {
const newComment = this.state.draft.slice(0, this.state.selection.start)
+ emoji + this.state.draft.slice(this.state.selection.end, this.state.draft.length);
this.setState(prevState => ({
selection: {
start: prevState.selection.start + emoji.length,
end: prevState.selection.start + emoji.length,
},
}));
this.updateDraft(newComment);
this.updateDraft(ReportUtils.insertText(this.state.draft, this.state.selection, emoji));
}

/**
Expand Down