Skip to content

Commit 24bc85c

Browse files
committed
fix(snippets): set first selected
1 parent c1099e7 commit 24bc85c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/renderer/components/sidebar/TheSidebar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const activeTab = ref<Tab>('library')
9595
9696
const onClickFolder = async (id: string) => {
9797
folderStore.selectId(id)
98-
snippetStore.setSnippetsByFolderIds()
98+
await snippetStore.setSnippetsByFolderIds(true)
9999
}
100100
101101
const onClickSystemFolder = (alias: SystemFolderAlias) => {

src/renderer/store/snippets.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,14 @@ export const useSnippetStore = defineStore('snippets', {
157157
await this.patchSnippetsById(this.selectedId!, body)
158158
await this.getSnippetsById(this.selectedId!)
159159
},
160-
async setSnippetsByFolderIds () {
160+
async setSnippetsByFolderIds (setFirst?: boolean) {
161161
const folderStore = useFolderStore()
162162
await this.getSnippetsByFolderIds(folderStore.selectedIds!)
163-
this.snippet = this.snippets[0]
163+
164+
if (setFirst) {
165+
this.snippet = this.snippets[0]
166+
store.app.set('selectedSnippetId', this.snippets[0].id)
167+
}
164168
},
165169
setSnippetsByAlias (alias: SystemFolderAlias) {
166170
const folderStore = useFolderStore()
@@ -192,6 +196,10 @@ export const useSnippetStore = defineStore('snippets', {
192196
store.app.set('selectedFolderAlias', alias)
193197
store.app.delete('selectedFolderId')
194198
store.app.delete('selectedFolderIds')
199+
},
200+
setSnippetById (id: string) {
201+
const snippet = this.all.find(i => i.id === id)
202+
if (snippet) this.snippet = snippet
195203
}
196204
}
197205
})

0 commit comments

Comments
 (0)