-
-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
web: add a simple command palette #7314
base: master
Are you sure you want to change the base?
Conversation
(selected) => (selected + 1) % filteredCommands.length | ||
); | ||
} | ||
if (e.key === "ArrowUp") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you keep these keyboard keys as an enum in a separate file to avoid using "magic strings".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, maybe we can take this up in a separate PR
Signed-off-by: 01zulfi <[email protected]>
Signed-off-by: 01zulfi <[email protected]>
Signed-off-by: 01zulfi <[email protected]>
Signed-off-by: 01zulfi <[email protected]>
Signed-off-by: 01zulfi <[email protected]>
c3946b4
to
7505704
Compare
Signed-off-by: 01zulfi <[email protected]>
Signed-off-by: 01zulfi <[email protected]>
apps/web/src/dialogs/command-palette/command-palette-dialog.tsx
Outdated
Show resolved
Hide resolved
function getMatchingIndices(text: string, query: string) { | ||
const indices: number[] = []; | ||
const set = new Set(query.toLowerCase()); | ||
const lowerText = text.toLowerCase(); | ||
|
||
for (let i = 0; i < lowerText.length; i++) { | ||
if (set.has(lowerText[i])) { | ||
indices.push(i); | ||
} | ||
} | ||
|
||
return indices; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super funky looking and I am not sure it does what we want it too. It'll just highlight all the matching characters which isn't strictly what we want. How about using surround
function from fuzzyjs
?
Signed-off-by: 01zulfi <[email protected]>
Signed-off-by: 01zulfi <[email protected]>
const result = queryClean.length > 0 ? match(queryClean, text) : false; | ||
|
||
return ( | ||
<span | ||
dangerouslySetInnerHTML={{ | ||
__html: | ||
result && result.match | ||
? surround(text, { | ||
result: result, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to use fuzzyjs's match
again here to be able to use surround
. Is this fine, or do you think we should refactor so that the lookup
in core
returns the object that surround
expects?
Signed-off-by: 01zulfi [email protected]