Skip to content

Commit

Permalink
🐛 検索クエリリセット後にスクロールを一番上から始めるように
Browse files Browse the repository at this point in the history
  • Loading branch information
SSlime-s committed Aug 20, 2023
1 parent 674b804 commit 1ac077e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/Main/CommandPalette/SearchResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ onBeforeUnmount(() => {
// 検索クエリを空にして Enter を押したときにリセットされるようにする
if (query.value === '') {
resetPaging()
noRestore()
}
})
Expand All @@ -125,7 +126,7 @@ const jumpToPage = (page: number) => {
}
}
const { didRender } = useKeepScrollPosition(
const { didRender, noRestore } = useKeepScrollPosition(
resultListEle,
computed(() => searchResult.value.map(message => message.id))
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Ref } from 'vue'
import { onBeforeUnmount } from 'vue'
import { onBeforeUnmount, ref } from 'vue'
import useOnAllRendered from './useOnAllRendered'
import { useCommandPalette } from '/@/store/app/commandPalette'
import type { MessageId } from '/@/types/entity-ids'
Expand All @@ -10,6 +10,10 @@ const useKeepScrollPosition = (
) => {
const { currentScrollTop } = useCommandPalette()
const { didRender, onAllRendered } = useOnAllRendered(list)
const isNoRestore = ref(false)
const noRestore = () => {
isNoRestore.value = true
}

// 開くときにマークダウンが描画しおえたらスクロール位置を適用
onAllRendered(() => {
Expand All @@ -21,11 +25,15 @@ const useKeepScrollPosition = (
// 閉じるときにスクロール位置を保持
onBeforeUnmount(() => {
if (ele.value) {
if (isNoRestore.value) {
currentScrollTop.value = 0
return
}
currentScrollTop.value = ele.value.scrollTop
}
})

return { didRender }
return { didRender, noRestore }
}

export default useKeepScrollPosition

0 comments on commit 1ac077e

Please sign in to comment.