Svelte refactoring ok

This commit is contained in:
Simon Cambier
2022-04-16 17:24:04 +02:00
parent 40aba85729
commit 832e782ba8
9 changed files with 300 additions and 230 deletions

View File

@@ -12,21 +12,16 @@ onMount(async () => {
input.select()
})
selectedNote.subscribe((note) => {
const elem = document.querySelector(`[data-note-id="${note?.path}"]`)
elem?.scrollIntoView({ behavior: "auto", block: "nearest" })
})
// const throttledMoveNoteSelection = throttle(moveNoteSelection, 75)
function moveNoteSelection(ev: KeyboardEvent): void {
switch (ev.key) {
case "ArrowDown":
selectedNote.next()
ev.preventDefault()
selectedNote.next()
break
case "ArrowUp":
selectedNote.previous()
ev.preventDefault()
selectedNote.previous()
break
case "ArrowLeft":
break
@@ -34,6 +29,7 @@ function moveNoteSelection(ev: KeyboardEvent): void {
break
case "Enter":
ev.preventDefault()
if (ev.ctrlKey || ev.metaKey) {
// Open in a new pane
dispatch("ctrl-enter", $selectedNote)
@@ -46,6 +42,14 @@ function moveNoteSelection(ev: KeyboardEvent): void {
}
break
}
// Scroll selected note into view when selecting with keyboard
if ($selectedNote) {
const elem = document.querySelector(
`[data-note-id="${$selectedNote.path}"]`
)
elem?.scrollIntoView({ behavior: "auto", block: "nearest" })
}
}
</script>