♻️ (scroll)

This commit is contained in:
Julien Calixte
2021-03-14 21:27:51 +01:00
parent 23a310f986
commit d624e064af
3 changed files with 33 additions and 18 deletions

View File

@@ -12,7 +12,7 @@ import { noteEventBus } from '@/bus/noteBusEvent'
import { useLinks } from '@/hooks/useLinks.hook'
import { useRepo } from '@/hooks/useRepo.hook'
import { NOTE_WIDTH } from '@/constants/note-width'
import { useOverlay } from '@/hooks/useOverlay.hook'
import { useFocus } from '@/hooks/useFocus.hook'
const sanitizePath = (path: string) => {
if (path.startsWith('./')) {
@@ -28,7 +28,7 @@ export const useNote = (
) => {
const { push } = useRouter()
const { query } = useRoute()
const { scrollTo } = useOverlay(false)
const { scrollToFocusedNote } = useFocus()
const stackedNotes = ref(
query.stackedNotes
@@ -61,18 +61,6 @@ export const useNote = (
}, {})
)
const scrollToFocusedNote = (sha?: string) => {
if (!sha) {
return
}
nextTick(() => {
const index = stackedNotes.value.findIndex((noteSHA) => noteSHA === sha)
const left = index * NOTE_WIDTH
scrollTo(left)
})
}
const unsubscribe = noteEventBus.addEventBusListener(
({ path, currentNoteSHA }) => {
const currentFile = tree.value.find((file) => file.sha === currentNoteSHA)
@@ -88,7 +76,7 @@ export const useNote = (
const file = tree.value.find((file) => file.path === finalPath)
if (!file?.sha || stackedNotes.value.includes(file.sha)) {
scrollToFocusedNote(file?.sha)
scrollToFocusedNote(stackedNotes.value, file?.sha)
return
}
@@ -127,7 +115,7 @@ export const useNote = (
stackedNotes.value = newStackedNotes
scrollToFocusedNote(file.sha)
scrollToFocusedNote(stackedNotes.value, file.sha)
}
)