mirror of
https://github.com/heyman/heynote.git
synced 2024-12-24 23:59:15 +01:00
Use fuzzysearch to filter notes in NoteSelector
This commit is contained in:
parent
d74499425e
commit
a95b043b12
6
package-lock.json
generated
6
package-lock.json
generated
@ -11,6 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sindresorhus/slugify": "^2.2.1",
|
"@sindresorhus/slugify": "^2.2.1",
|
||||||
"electron-log": "^5.0.1",
|
"electron-log": "^5.0.1",
|
||||||
|
"fuzzysort": "^3.0.2",
|
||||||
"pinia": "^2.1.7",
|
"pinia": "^2.1.7",
|
||||||
"semver": "^7.6.3"
|
"semver": "^7.6.3"
|
||||||
},
|
},
|
||||||
@ -3833,6 +3834,11 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/fuzzysort": {
|
||||||
|
"version": "3.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/fuzzysort/-/fuzzysort-3.0.2.tgz",
|
||||||
|
"integrity": "sha512-ZyahVgxvckB1Qosn7YGWLDJJp2XlyaQ2WmZeI+d0AzW0AMqVYnz5N89G6KAKa6m/LOtv+kzJn4lhDF/yVg11Cg=="
|
||||||
|
},
|
||||||
"node_modules/get-caller-file": {
|
"node_modules/get-caller-file": {
|
||||||
"version": "2.0.5",
|
"version": "2.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
||||||
|
@ -80,6 +80,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sindresorhus/slugify": "^2.2.1",
|
"@sindresorhus/slugify": "^2.2.1",
|
||||||
"electron-log": "^5.0.1",
|
"electron-log": "^5.0.1",
|
||||||
|
"fuzzysort": "^3.0.2",
|
||||||
"pinia": "^2.1.7",
|
"pinia": "^2.1.7",
|
||||||
"semver": "^7.6.3"
|
"semver": "^7.6.3"
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import fuzzysort from 'fuzzysort'
|
||||||
|
|
||||||
import { mapState, mapActions } from 'pinia'
|
import { mapState, mapActions } from 'pinia'
|
||||||
import { toRaw } from 'vue';
|
import { toRaw } from 'vue';
|
||||||
import { useNotesStore } from "../stores/notes-store"
|
import { useNotesStore } from "../stores/notes-store"
|
||||||
@ -61,9 +63,21 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
filteredItems() {
|
filteredItems() {
|
||||||
return this.orderedItems.filter((lang) => {
|
if (this.filter === "") {
|
||||||
return lang.name.toLowerCase().indexOf(this.filter.toLowerCase()) !== -1
|
return this.orderedItems
|
||||||
|
} else {
|
||||||
|
const searchResults = fuzzysort.go(this.filter, this.items, {
|
||||||
|
keys: ["name", "folder"],
|
||||||
})
|
})
|
||||||
|
return searchResults.map((result) => {
|
||||||
|
const obj = {...result.obj}
|
||||||
|
const nameHighlight = result[0].highlight("<b>", "</b>")
|
||||||
|
const folderHighlight = result[1].highlight("<b>", "</b>")
|
||||||
|
obj.name = nameHighlight !== "" ? nameHighlight : obj.name
|
||||||
|
obj.folder = folderHighlight !== "" ? folderHighlight : obj.folder
|
||||||
|
return obj
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -74,7 +88,11 @@
|
|||||||
|
|
||||||
onKeydown(event) {
|
onKeydown(event) {
|
||||||
if (event.key === "ArrowDown") {
|
if (event.key === "ArrowDown") {
|
||||||
|
if (this.selected === this.filteredItems.length - 1) {
|
||||||
|
this.selected = 0
|
||||||
|
} else {
|
||||||
this.selected = Math.min(this.selected + 1, this.filteredItems.length - 1)
|
this.selected = Math.min(this.selected + 1, this.filteredItems.length - 1)
|
||||||
|
}
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (this.selected === this.filteredItems.length - 1) {
|
if (this.selected === this.filteredItems.length - 1) {
|
||||||
this.$refs.container.scrollIntoView({block: "end"})
|
this.$refs.container.scrollIntoView({block: "end"})
|
||||||
@ -83,7 +101,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (event.key === "ArrowUp") {
|
} else if (event.key === "ArrowUp") {
|
||||||
|
if (this.selected === 0) {
|
||||||
|
this.selected = this.filteredItems.length - 1
|
||||||
|
} else {
|
||||||
this.selected = Math.max(this.selected - 1, 0)
|
this.selected = Math.max(this.selected - 1, 0)
|
||||||
|
}
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (this.selected === 0) {
|
if (this.selected === 0) {
|
||||||
this.$refs.container.scrollIntoView({block: "start"})
|
this.$refs.container.scrollIntoView({block: "start"})
|
||||||
@ -143,8 +165,8 @@
|
|||||||
@click="selectItem(item.path)"
|
@click="selectItem(item.path)"
|
||||||
ref="item"
|
ref="item"
|
||||||
>
|
>
|
||||||
<span class="name">{{ item.name }}</span>
|
<span class="name" v-html="item.name" />
|
||||||
<span class="path">{{ item.folder }}</span>
|
<span class="path" v-html="item.folder" />
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
@ -231,6 +253,8 @@
|
|||||||
overflow: hidden
|
overflow: hidden
|
||||||
text-overflow: ellipsis
|
text-overflow: ellipsis
|
||||||
text-wrap: nowrap
|
text-wrap: nowrap
|
||||||
|
::v-deep b
|
||||||
|
font-weight: 700
|
||||||
.path
|
.path
|
||||||
opacity: 0.6
|
opacity: 0.6
|
||||||
font-size: 12px
|
font-size: 12px
|
||||||
@ -238,4 +262,6 @@
|
|||||||
overflow: hidden
|
overflow: hidden
|
||||||
text-overflow: ellipsis
|
text-overflow: ellipsis
|
||||||
text-wrap: nowrap
|
text-wrap: nowrap
|
||||||
|
::v-deep b
|
||||||
|
font-weight: 700
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user