refactor(component): cmdk ordering (#5722)

Replace internal CMDK command filtering/sorting logic.
The new implementation includes the following for command scoring:
- categories weights
- highlighted fragments
- original command score value

The new logic should be much cleaner and remove some hacks in the original implementation.

Not sure if this is optimal yet. Could be changed later.

fix https://github.com/toeverything/AFFiNE/issues/5699
This commit is contained in:
Peng Xiao committed 2024-02-16 13:20:24 +00:00
1 parent 9e7eb5629c
commit d1c4e6141a
13 files changed
+304 -189

No files matched your search

+5 -3
View File
@@ -24,10 +24,12 @@ const insertInputText = async (page: Page, text: string) => {
const keyboardDownAndSelect = async (page: Page, label: string) => {
await page.keyboard.press('ArrowDown');
const selectedEl = page.locator(
'[cmdk-item][data-selected] [data-testid="cmdk-label"]'
);
if (
(await page
.locator('[cmdk-item][data-selected] [data-testid="cmdk-label"]')
.innerText()) !== label
!(await selectedEl.isVisible()) ||
(await selectedEl.innerText()) !== label
) {
await keyboardDownAndSelect(page, label);
} else {