Skip to content

Commit a7968ee

Browse files
committed
simplify attachTribute, remove booleans
1 parent 9e73deb commit a7968ee

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

web_src/js/features/comp/ComboMarkdownEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export class ComboMarkdownEditor {
363363
},
364364
});
365365
this.applyEditorHeights(this.container.querySelector('.CodeMirror-scroll'), this.options.editorHeights);
366-
await attachTribute(this.easyMDE.codemirror.getInputField(), true, true);
366+
await attachTribute(this.easyMDE.codemirror.getInputField());
367367
if (this.dropzone) {
368368
initEasyMDEPaste(this.easyMDE, this.dropzone);
369369
}

web_src/js/features/tribute.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {htmlEscape} from 'escape-goat';
33

44
type TributeItem = Record<string, any>;
55

6-
function makeCollections(mentions: boolean, emoji: boolean) {
7-
const collections = [];
6+
export async function attachTribute(element: HTMLElement) {
7+
const {default: Tribute} = await import(/* webpackChunkName: "tribute" */'tributejs');
88

9-
if (emoji) {
10-
collections.push({
9+
const collections = [
10+
{ // emojis
1111
trigger: ':',
1212
requireLeadingSpace: true,
1313
values: (query: string, cb: (matches: Array<string>) => void) => {
@@ -28,11 +28,7 @@ function makeCollections(mentions: boolean, emoji: boolean) {
2828
menuItemTemplate: (item: TributeItem) => {
2929
return `<div class="tribute-item">${emojiHTML(item.original)}<span>${htmlEscape(item.original)}</span></div>`;
3030
},
31-
});
32-
}
33-
34-
if (mentions) {
35-
collections.push({
31+
}, { // mentions
3632
values: window.config.mentionValues ?? [],
3733
requireLeadingSpace: true,
3834
menuItemTemplate: (item: TributeItem) => {
@@ -44,15 +40,9 @@ function makeCollections(mentions: boolean, emoji: boolean) {
4440
</div>
4541
`;
4642
},
47-
});
48-
}
43+
},
44+
];
4945

50-
return collections;
51-
}
52-
53-
export async function attachTribute(element: HTMLElement, mentions: boolean, emoji: boolean) {
54-
const {default: Tribute} = await import(/* webpackChunkName: "tribute" */'tributejs');
55-
const collections = makeCollections(mentions, emoji);
5646
// @ts-expect-error TS2351: This expression is not constructable (strange, why)
5747
const tribute = new Tribute({collection: collections, noMatchTemplate: ''});
5848
tribute.attach(element);

0 commit comments

Comments
 (0)