✨ (scroll) scroll on title click
This commit is contained in:
@@ -1,14 +1,23 @@
|
||||
import { NOTE_WIDTH } from '@/constants/note-width'
|
||||
import { useOverlay } from '@/hooks/useOverlay.hook'
|
||||
import { nextTick } from 'vue'
|
||||
import { LocationQueryValue } from 'vue-router'
|
||||
import { computed, nextTick } from 'vue'
|
||||
import { LocationQueryValue, useRoute } from 'vue-router'
|
||||
|
||||
export const useFocus = () => {
|
||||
const { scrollToNote } = useOverlay(false)
|
||||
const { query } = useRoute()
|
||||
|
||||
const initialStackedNotes = computed(() =>
|
||||
query.stackedNotes
|
||||
? Array.isArray(query.stackedNotes)
|
||||
? query.stackedNotes
|
||||
: [query.stackedNotes]
|
||||
: []
|
||||
)
|
||||
|
||||
const scrollToFocusedNote = (
|
||||
stackedNotes: LocationQueryValue[],
|
||||
sha?: string
|
||||
sha?: string,
|
||||
stackedNotes: LocationQueryValue[] = initialStackedNotes.value
|
||||
) => {
|
||||
if (!sha) {
|
||||
return
|
||||
|
||||
@@ -61,7 +61,7 @@ export const useNote = (
|
||||
}, {})
|
||||
)
|
||||
|
||||
const unsubscribe = noteEventBus.addEventBusListener(
|
||||
const unsubscribeLink = noteEventBus.addEventBusListener(
|
||||
({ path, currentNoteSHA }) => {
|
||||
const currentFile = tree.value.find((file) => file.sha === currentNoteSHA)
|
||||
|
||||
@@ -76,7 +76,7 @@ export const useNote = (
|
||||
const file = tree.value.find((file) => file.path === finalPath)
|
||||
|
||||
if (!file?.sha || stackedNotes.value.includes(file.sha)) {
|
||||
scrollToFocusedNote(stackedNotes.value, file?.sha)
|
||||
scrollToFocusedNote(file?.sha, stackedNotes.value)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ export const useNote = (
|
||||
|
||||
stackedNotes.value = newStackedNotes
|
||||
|
||||
scrollToFocusedNote(stackedNotes.value, file.sha)
|
||||
scrollToFocusedNote(file.sha, stackedNotes.value)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -140,7 +140,7 @@ export const useNote = (
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
unsubscribe()
|
||||
unsubscribeLink()
|
||||
})
|
||||
|
||||
watch(stackedNotes, resizeContainer, {
|
||||
|
||||
Reference in New Issue
Block a user