2022-04-01 13:02:35 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import emojis from "./emoji.json";
|
2022-04-21 11:57:45 +00:00
|
|
|
import { matchBefore } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
2022-04-01 13:02:35 +00:00
|
|
|
|
|
|
|
const emojiMatcher = /\(([^\)]+)\)\s+(.+)$/;
|
|
|
|
|
|
|
|
export async function emojiCompleter() {
|
2022-04-04 13:25:07 +00:00
|
|
|
let prefix = await matchBefore(":[\\w]+");
|
2022-04-01 13:02:35 +00:00
|
|
|
if (!prefix) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const textPrefix = prefix.text.substring(1); // Cut off the initial :
|
|
|
|
let filteredEmoji = emojis.filter(([_, shortcode]) =>
|
|
|
|
shortcode.includes(textPrefix)
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
from: prefix.from,
|
|
|
|
filter: false,
|
|
|
|
options: filteredEmoji.map(([emoji, shortcode]) => ({
|
|
|
|
detail: shortcode,
|
|
|
|
label: emoji,
|
|
|
|
type: "emoji",
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
}
|