Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
222d04fb
Commit
222d04fb
authored
Feb 24, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: add fuse to get tag suggestions
parent
68468927
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
21 deletions
+13
-21
package.json
web/package.json
+1
-0
pnpm-lock.yaml
web/pnpm-lock.yaml
+8
-0
TagSuggestions.tsx
web/src/components/MemoEditor/Editor/TagSuggestions.tsx
+4
-21
No files found.
web/package.json
View file @
222d04fb
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
"axios"
:
"^1.6.7"
,
"axios"
:
"^1.6.7"
,
"classnames"
:
"^2.5.1"
,
"classnames"
:
"^2.5.1"
,
"copy-to-clipboard"
:
"^3.3.3"
,
"copy-to-clipboard"
:
"^3.3.3"
,
"fuse.js"
:
"^7.0.0"
,
"highlight.js"
:
"^11.9.0"
,
"highlight.js"
:
"^11.9.0"
,
"i18next"
:
"^21.10.0"
,
"i18next"
:
"^21.10.0"
,
"i18next-browser-languagedetector"
:
"^7.2.0"
,
"i18next-browser-languagedetector"
:
"^7.2.0"
,
...
...
web/pnpm-lock.yaml
View file @
222d04fb
...
@@ -32,6 +32,9 @@ dependencies:
...
@@ -32,6 +32,9 @@ dependencies:
copy-to-clipboard
:
copy-to-clipboard
:
specifier
:
^3.3.3
specifier
:
^3.3.3
version
:
3.3.3
version
:
3.3.3
fuse.js
:
specifier
:
^7.0.0
version
:
7.0.0
highlight.js
:
highlight.js
:
specifier
:
^11.9.0
specifier
:
^11.9.0
version
:
11.9.0
version
:
11.9.0
...
@@ -3114,6 +3117,11 @@ packages:
...
@@ -3114,6 +3117,11 @@ packages:
resolution
:
{
integrity
:
sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==
}
resolution
:
{
integrity
:
sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==
}
dev
:
true
dev
:
true
/fuse.js@7.0.0
:
resolution
:
{
integrity
:
sha512-14F4hBIxqKvD4Zz/XjDc3y94mNZN6pRv3U13Udo0lNLCWRBUsrMv2xwcF/y/Z5sV6+FQW+/ow68cHpm4sunt8Q==
}
engines
:
{
node
:
'
>=10'
}
dev
:
false
/gensync@1.0.0-beta.2
:
/gensync@1.0.0-beta.2
:
resolution
:
{
integrity
:
sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==
}
resolution
:
{
integrity
:
sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==
}
engines
:
{
node
:
'
>=6.9.0'
}
engines
:
{
node
:
'
>=6.9.0'
}
...
...
web/src/components/MemoEditor/Editor/TagSuggestions.tsx
View file @
222d04fb
import
classNames
from
"classnames"
;
import
classNames
from
"classnames"
;
import
Fuse
from
"fuse.js"
;
import
{
useEffect
,
useRef
,
useState
}
from
"react"
;
import
{
useEffect
,
useRef
,
useState
}
from
"react"
;
import
getCaretCoordinates
from
"textarea-caret"
;
import
getCaretCoordinates
from
"textarea-caret"
;
import
OverflowTip
from
"@/components/kit/OverflowTip"
;
import
OverflowTip
from
"@/components/kit/OverflowTip"
;
...
@@ -35,27 +36,9 @@ const TagSuggestions = ({ editorRef, editorActions }: Props) => {
...
@@ -35,27 +36,9 @@ const TagSuggestions = ({ editorRef, editorActions }: Props) => {
const
suggestionsRef
=
useRef
<
string
[]
>
([]);
const
suggestionsRef
=
useRef
<
string
[]
>
([]);
suggestionsRef
.
current
=
(()
=>
{
suggestionsRef
.
current
=
(()
=>
{
const
input
=
getCurrentWord
()[
0
].
slice
(
1
).
toLowerCase
();
const
search
=
getCurrentWord
()[
0
].
slice
(
1
).
toLowerCase
();
const
fuse
=
new
Fuse
(
tagsRef
.
current
);
const
customMatches
=
(
tag
:
string
,
input
:
string
)
=>
{
return
fuse
.
search
(
search
).
map
((
result
)
=>
result
.
item
);
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
isVisibleRef
=
useRef
(
false
);
const
isVisibleRef
=
useRef
(
false
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment