Fix some nasty bug

This commit is contained in:
Zef Hemel
2022-04-01 15:02:35 +02:00
parent 4d201efdbb
commit b858917c98
13 changed files with 115 additions and 37 deletions
+2 -2
View File
@@ -79,8 +79,8 @@ export async function updateMaterializedQueriesOnPage(pageName: string) {
for (let {
key,
page,
value: {item, children},
} of await syscall("index.scanPrefixGlobal", "it:")) {
value: { item, children },
}; of await syscall("index.scanPrefixGlobal", "it:")) {
let [, pos] = key.split(":");
if (!filter || (filter && item.includes(filter))) {
results.push(`* [[${page}@${pos}]] ${item}`);
+1
View File
@@ -0,0 +1 @@
emoji-data.txt
+3
View File
@@ -0,0 +1,3 @@
build:
curl https://unicode.org/Public/emoji/14.0/emoji-test.txt > emoji-data.txt
node build.js
+17
View File
@@ -0,0 +1,17 @@
// Generates emoji.json from emoji-data.txt
const { readFileSync, writeFileSync } = require("fs");
const emojiRe = /#\s([^\s]+)\s+E[^\s]+\s+(.+)$/;
let text = readFileSync("emoji-data.txt", "utf-8");
const lines = text.split("\n").filter((line) => !line.startsWith("#"));
let emoji = [];
for (const line of lines) {
let match = emojiRe.exec(line);
if (match) {
emoji.push([match[1], match[2].toLowerCase().replaceAll(/\W+/g, "_")]);
}
}
writeFileSync("emoji.json", JSON.stringify(emoji));
+4
View File
@@ -0,0 +1,4 @@
functions:
emojiCompleter:
path: "./emoji.ts:emojiCompleter"
isCompleter: true
+26
View File
@@ -0,0 +1,26 @@
// @ts-ignore
import emojis from "./emoji.json";
import { syscall } from "../lib/syscall";
const emojiMatcher = /\(([^\)]+)\)\s+(.+)$/;
export async function emojiCompleter() {
let prefix = await syscall("editor.matchBefore", ":[\\w\\s]*");
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",
})),
};
}