1
0
silverbullet/plugs/emoji/emoji.ts
Zef Hemel 3545d00d46
Major mini editor refactoring (#225)
Replaces most editing components with CM components, enabling vim mode and completions everywhere

Fixes #205 
Fixes #221 
Fixes #222 
Fixes #223
2022-12-21 14:55:24 +01:00

26 lines
622 B
TypeScript

import emojis from "./emoji.json" assert { type: "json" };
import type { CompleteEvent } from "../../plug-api/app_event.ts";
export function emojiCompleter({ linePrefix, pos }: CompleteEvent) {
const match = /:([\w]+)$/.exec(linePrefix);
if (!match) {
return null;
}
const [fullMatch, emojiName] = match;
const filteredEmoji = emojis.filter(([_, shortcode]) =>
shortcode.includes(emojiName)
);
return {
from: pos - fullMatch.length,
filter: false,
options: filteredEmoji.map(([emoji, shortcode]) => ({
detail: shortcode,
label: emoji,
type: "emoji",
})),
};
}