|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import classNames from "classnames";
|
|
|
|
|
import Fuse from "fuse.js";
|
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
|
import getCaretCoordinates from "textarea-caret";
|
|
|
|
|
import OverflowTip from "@/components/kit/OverflowTip";
|
|
|
|
@ -35,27 +36,9 @@ const TagSuggestions = ({ editorRef, editorActions }: Props) => {
|
|
|
|
|
|
|
|
|
|
const suggestionsRef = useRef<string[]>([]);
|
|
|
|
|
suggestionsRef.current = (() => {
|
|
|
|
|
const input = getCurrentWord()[0].slice(1).toLowerCase();
|
|
|
|
|
|
|
|
|
|
const customMatches = (tag: string, input: string) => {
|
|
|
|
|
const tagLowerCase = tag.toLowerCase();
|
|
|
|
|
const inputLowerCase = input.toLowerCase();
|
|
|
|
|
let inputIndex = 0;
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < tagLowerCase.length; i++) {
|
|
|
|
|
if (tagLowerCase[i] === inputLowerCase[inputIndex]) {
|
|
|
|
|
inputIndex++;
|
|
|
|
|
if (inputIndex === inputLowerCase.length) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const matchedTags = tagsRef.current.filter((tag) => customMatches(tag, input));
|
|
|
|
|
return matchedTags.slice(0, 5);
|
|
|
|
|
const search = getCurrentWord()[0].slice(1).toLowerCase();
|
|
|
|
|
const fuse = new Fuse(tagsRef.current);
|
|
|
|
|
return fuse.search(search).map((result) => result.item);
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
const isVisibleRef = useRef(false);
|
|
|
|
|