Skip to content
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

upd: bring back fuzzy search #831

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/components/Actions/SimpleAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IKeyBindingConfig } from './KeyBinding'
import { EventDispatcher } from '/@/components/Common/Event/EventDispatcher'
import { v4 as uuid } from 'uuid'
import { translate } from '../Locales/Manager'

export interface IActionConfig {
type?: 'action'
Expand Down Expand Up @@ -45,6 +46,13 @@ export class SimpleAction extends EventDispatcher<void> {
}
//#endregion

get translatedName() {
return translate(this.name)
}
get translatedDescription() {
return translate(this.description)
}

getConfig() {
return this.config
}
Expand Down
39 changes: 37 additions & 2 deletions src/components/CommandBar/CommandBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@
transition: 'slide-y-transition',
contentClass: 'commandbar-menu elevation-4',
}"
:items="actions"
:items="processedActions"
:item-text="(item) => `${t(item.name)}\n${t(item.description)}`"
:item-value="(item) => item"
:placeholder="t('general.search')"
:filter="filter"
:cache-items="false"
auto-select-first
:autofocus="autofocus"
v-model="currentItem"
:value="currentItem"
@change="onSelectedAction"
@focus="updateActions"
@blur="$emit('blur')"
@update:search-input="onUpdateSearchInput"
spellcheck="false"
>
<template v-slot:no-data>
<v-list-item>
Expand Down Expand Up @@ -58,6 +62,8 @@ import { CommandBarExtensionItems } from '../Extensions/Scripts/Modules/CommandB
import { getDefaultFileIcon } from '/@/utils/file/getIcon'
import { devActions } from '../Developer/Actions'
import { getCommandBarActions } from './State'
import { QuickScore } from 'quick-score'
import { markRaw } from 'vue'

export default {
props: {
Expand All @@ -71,6 +77,7 @@ export default {

return {
t,
quickScore: null,
}
},
async mounted() {
Expand All @@ -89,6 +96,7 @@ export default {
data: () => ({
currentItem: '',
actions: [],
processedActions: [],
disposables: [],
}),
methods: {
Expand All @@ -109,6 +117,33 @@ export default {
...extensionActions,
...getCommandBarActions(),
]
this.quickScore = markRaw(new QuickScore(this.actions))
this.processedActions = this.actions
},
onUpdateSearchInput(searchInput) {
console.log(searchInput, this.quickScore)
if (!this.quickScore) return

if (searchInput === null || searchInput === '') {
this.processedActions = this.actions
return
}

this.processedActions = this.quickScore
.search(searchInput, [
'translatedName',
'translatedDescription',
])
.map(({ item }) => item)
console.log(this.processedActions)

this.$nextTick(() => {
this.currentItem = searchInput
console.log(this.currentItem)
})
},
filter() {
return 1
},
onSelectedAction(item) {
this.$nextTick(() => (this.currentItem = ''))
Expand Down