mirror of
https://github.com/heyman/heynote.git
synced 2025-01-11 00:18:29 +01:00
Use fuzzysort to filter languages
This commit is contained in:
parent
2f7374cca9
commit
43652ccaa9
@ -1,4 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import fuzzysort from 'fuzzysort'
|
||||||
import { LANGUAGES } from '../editor/languages.js'
|
import { LANGUAGES } from '../editor/languages.js'
|
||||||
|
|
||||||
const items = LANGUAGES.map(l => {
|
const items = LANGUAGES.map(l => {
|
||||||
@ -11,6 +12,10 @@
|
|||||||
})
|
})
|
||||||
items.unshift({token: "auto", name:"Auto-detect"})
|
items.unshift({token: "auto", name:"Auto-detect"})
|
||||||
|
|
||||||
|
items.forEach((item, idx) => {
|
||||||
|
item.preparedName = fuzzysort.prepare(item.name)
|
||||||
|
})
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -26,8 +31,17 @@
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
filteredItems() {
|
filteredItems() {
|
||||||
return items.filter((lang) => {
|
if (this.filter === "") {
|
||||||
return lang.name.toLowerCase().indexOf(this.filter.toLowerCase()) !== -1
|
return items
|
||||||
|
}
|
||||||
|
const searchResults = fuzzysort.go(this.filter, items, {
|
||||||
|
keys: ['name'],
|
||||||
|
})
|
||||||
|
return searchResults.map(result => {
|
||||||
|
return {
|
||||||
|
"token": result.obj.token,
|
||||||
|
"name": result[0].highlight("<b>", "</b>")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -96,9 +110,8 @@
|
|||||||
:class="idx === selected ? 'selected' : ''"
|
:class="idx === selected ? 'selected' : ''"
|
||||||
@click="selectItem(item.token)"
|
@click="selectItem(item.token)"
|
||||||
ref="item"
|
ref="item"
|
||||||
>
|
v-html="item.name"
|
||||||
{{ item.name }}
|
/>
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -173,4 +186,6 @@
|
|||||||
&.selected
|
&.selected
|
||||||
background: #1b6540
|
background: #1b6540
|
||||||
color: rgba(255,255,255, 0.87)
|
color: rgba(255,255,255, 0.87)
|
||||||
|
::v-deep b
|
||||||
|
font-weight: 700
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user