File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed
shared/types/renderer/composable Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ import parserMarkdown from 'prettier/parser-markdown'
4646import parserPostcss from ' prettier/parser-postcss'
4747import parserYaml from ' prettier/parser-yaml'
4848import { emitter } from ' @/composable'
49+ import { useFolderStore } from ' @/store/folders'
4950
5051interface Props {
5152 lang: Language
@@ -69,6 +70,7 @@ const emit = defineEmits<Emits>()
6970
7071const appStore = useAppStore ()
7172const snippetStore = useSnippetStore ()
73+ const folderStore = useFolderStore ()
7274
7375const editorRef = ref ()
7476const cursorPosition = reactive ({
@@ -136,9 +138,12 @@ const init = async () => {
136138 editor .selection .on (' changeCursor' , () => {
137139 getCursorPosition ()
138140 })
139- editor .on (' focus' , () => {
141+ editor .on (' focus' , async () => {
140142 if (snippetStore .searchQuery ?.length ) {
141143 snippetStore .searchQuery = undefined
144+ folderStore .selectId (snippetStore .selected ! .folderId )
145+ await snippetStore .setSnippetsByFolderIds ()
146+ emitter .emit (' scroll-to:snippet' , snippetStore .selectedId ! )
142147 }
143148 })
144149
Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ const listRef = ref()
4545const bodyRef = ref <HTMLElement >()
4646const gutterRef = ref ()
4747
48+ const scrollToSnippet = (id : string ) => {
49+ const el = document .querySelector <HTMLElement >(` [data-id='${id }'] ` )
50+ if (el ?.offsetTop ) setScrollPosition (bodyRef .value ! , el .offsetTop )
51+ }
52+
4853onMounted (() => {
4954 interact (listRef .value ).resizable ({
5055 allowFrom: gutterRef .value ,
@@ -62,20 +67,20 @@ onMounted(() => {
6267
6368watch (
6469 () => appStore .isInit ,
65- () => {
66- const el = document .querySelector <HTMLElement >(
67- ` [data-id='${snippetStore .selectedId ! }'] `
68- )
69- if (el ?.offsetTop ) setScrollPosition (bodyRef .value ! , el .offsetTop )
70- }
70+ () => scrollToSnippet (snippetStore .selectedId ! )
7171)
7272
7373emitter .on (' folder:click' , () => {
7474 setScrollPosition (bodyRef .value ! , 0 )
7575})
7676
77+ emitter .on (' scroll-to:snippet' , (id : string ) => {
78+ scrollToSnippet (id )
79+ })
80+
7781onUnmounted (() => {
7882 emitter .off (' folder:click' )
83+ emitter .off (' scroll-to:snippet' )
7984})
8085 </script >
8186
Original file line number Diff line number Diff line change @@ -4,5 +4,6 @@ export type EmitterEvents = {
44 'folder:click' : any
55 'folder:rename' : string
66 'scroll-to:folder' : string
7+ 'scroll-to:snippet' : string
78 'search:focus' : boolean
89}
You can’t perform that action at this time.
0 commit comments