Skip to content

Commit

Permalink
Merge pull request #7943 from RocketChat/firefox-emoji
Browse files Browse the repository at this point in the history
[FIX] Broken emoji picker on firefox
  • Loading branch information
rodrigok committed Aug 30, 2017
1 parent 5568591 commit fc3fd84
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 1 addition & 3 deletions packages/rocketchat-emoji/client/emojiButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ Template.messageBox.events({
const caretPos = input.selectionStart;
const textAreaTxt = input.value;
input.focus();
if (document.execCommand) {
document.execCommand('insertText', false, emojiValue);
} else {
if (!document.execCommand || !document.execCommand('insertText', false, emojiValue)) {
input.value = textAreaTxt.substring(0, caretPos) + emojiValue + textAreaTxt.substring(caretPos);
}

Expand Down
10 changes: 4 additions & 6 deletions packages/rocketchat-ui-message/client/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ function applyMd(e, t) {
box.selectionStart = selectionStart - startPattern.length;
box.selectionEnd = selectionEnd + endPattern.length;

if (document.execCommand) {
document.execCommand('insertText', false, selectedText);
} else {
if (!document.execCommand || !document.execCommand('insertText', false, selectedText)) {
box.value = initText.substr(0, initText.length - startPattern.length) + selectedText + finalText.substr(endPattern.length);
}

box.selectionStart = selectionStart - startPattern.length;
box.selectionEnd = box.selectionStart + selectedText.length;
$(box).change();
Expand All @@ -68,11 +67,10 @@ function applyMd(e, t) {
apply pattern
restore selection
*/
if (document.execCommand) {
document.execCommand('insertText', false, this.pattern.replace('{{text}}', selectedText));
} else {
if (!document.execCommand || !document.execCommand('insertText', false, this.pattern.replace('{{text}}', selectedText))) {
box.value = initText + this.pattern.replace('{{text}}', selectedText) + finalText;
}

box.selectionStart = selectionStart + this.pattern.indexOf('{{text}}');
box.selectionEnd = box.selectionStart + selectedText.length;
$(box).change();
Expand Down

0 comments on commit fc3fd84

Please sign in to comment.