mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 11:52:45 +08:00
DEV: Export add emoji logic in textarea manipulation mixin (#14976)
This commit is contained in:
parent
19fb97bb13
commit
1b752a5dec
|
@ -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;
|
||||
|
|
|
@ -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}:`);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user