DEV: Export add emoji logic in textarea manipulation mixin (#14976)

This commit is contained in:
Mark VanLandingham 2021-11-16 13:42:21 -06:00 committed by GitHub
parent 19fb97bb13
commit 1b752a5dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 23 deletions

View File

@ -22,7 +22,6 @@ import deprecated from "discourse-common/lib/deprecated";
import discourseDebounce from "discourse-common/lib/debounce";
import { findRawTemplate } from "discourse-common/lib/raw-templates";
import { getRegister } from "discourse-common/lib/get-owner";
import { isEmpty } from "@ember/utils";
import { isTesting } from "discourse-common/config/environment";
import { linkSeenHashtags } from "discourse/lib/link-hashtags";
import { linkSeenMentions } from "discourse/lib/link-mentions";
@ -794,28 +793,6 @@ export default Component.extend(TextareaTextManipulation, {
this.set("emojiPickerIsActive", !this.emojiPickerIsActive);
},
emojiSelected(code) {
let selected = this._getSelected();
const captures = selected.pre.match(/\B:(\w*)$/);
if (isEmpty(captures)) {
if (selected.pre.match(/\S$/)) {
this._addText(selected, ` :${code}:`);
} else {
this._addText(selected, `:${code}:`);
}
} else {
let numOfRemovedChars = selected.pre.length - captures[1].length;
selected.pre = selected.pre.slice(
0,
selected.pre.length - captures[1].length
);
selected.start -= numOfRemovedChars;
selected.end -= numOfRemovedChars;
this._addText(selected, `${code}:`);
}
},
toolbarButton(button) {
if (this.disabled) {
return;

View File

@ -1,6 +1,8 @@
import { bind } from "discourse-common/utils/decorators";
import Mixin from "@ember/object/mixin";
import toMarkdown from "discourse/lib/to-markdown";
import { action } from "@ember/object";
import { isEmpty } from "@ember/utils";
import { isTesting } from "discourse-common/config/environment";
import {
clipboardHelpers,
@ -288,4 +290,27 @@ export default Mixin.create({
e.preventDefault();
}
},
@action
emojiSelected(code) {
let selected = this._getSelected();
const captures = selected.pre.match(/\B:(\w*)$/);
if (isEmpty(captures)) {
if (selected.pre.match(/\S$/)) {
this._addText(selected, ` :${code}:`);
} else {
this._addText(selected, `:${code}:`);
}
} else {
let numOfRemovedChars = selected.pre.length - captures[1].length;
selected.pre = selected.pre.slice(
0,
selected.pre.length - captures[1].length
);
selected.start -= numOfRemovedChars;
selected.end -= numOfRemovedChars;
this._addText(selected, `${code}:`);
}
},
});