Skip to content

A platform for community discussion. Free, open, simple.

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

Mark VanLandingham1b752a5dec99
diff --git a/app/assets/javascripts/discourse/app/components/d-editor.js b/app/assets/javascripts/discourse/app/components/d-editor.js
index 13f589fba46..1b0ce15734a 100644
--- a/app/assets/javascripts/discourse/app/components/d-editor.js
+++ b/app/assets/javascripts/discourse/app/components/d-editor.js
@@ -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;
diff --git a/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js b/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js
index b8253943d9d..02563526b13 100644
--- a/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js
+++ b/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js
@@ -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}:`);
+ }
+ },
});