Small fixes / cleaner code
This commit is contained in:
@@ -20,14 +20,11 @@ let searchQuery: string
|
||||
let resultNotes: ResultNote[] = []
|
||||
$: selectedNote = resultNotes[selectedIndex]
|
||||
|
||||
$: (async() => {
|
||||
if (searchQuery) {
|
||||
resultNotes = await getSuggestions(searchQuery)
|
||||
lastSearch = searchQuery
|
||||
}
|
||||
selectedIndex = 0
|
||||
scrollIntoView()
|
||||
})()
|
||||
$: if (searchQuery) {
|
||||
updateResults()
|
||||
} else {
|
||||
resultNotes = []
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
searchQuery = lastSearch
|
||||
@@ -39,6 +36,14 @@ onMount(() => {
|
||||
eventBus.on("vault", "arrow-down", () => moveIndex(1))
|
||||
})
|
||||
|
||||
async function updateResults() {
|
||||
resultNotes = await getSuggestions(searchQuery)
|
||||
lastSearch = searchQuery
|
||||
selectedIndex = 0
|
||||
scrollIntoView()
|
||||
if (resultNotes.length) console.log(resultNotes[0])
|
||||
}
|
||||
|
||||
function onClick() {
|
||||
if (!selectedNote) return
|
||||
openNote(selectedNote)
|
||||
|
||||
@@ -89,7 +89,7 @@ export function makeExcerpt(content: string, offset: number): string {
|
||||
const pos = offset ?? -1
|
||||
if (pos > -1) {
|
||||
const from = Math.max(0, pos - excerptBefore)
|
||||
const to = Math.min(content.length - 1, pos + excerptAfter)
|
||||
const to = Math.min(content.length, pos + excerptAfter)
|
||||
content =
|
||||
(from > 0 ? '…' : '') +
|
||||
content.slice(from, to).trim() +
|
||||
|
||||
Reference in New Issue
Block a user