Skip to content

Commit

Permalink
feat(snippets): add new fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Mar 29, 2022
1 parent 60f35d7 commit fa1e828
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/renderer/components/snippets/SnippetHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<UniconsArrow />
</AppActionButton>
<AppActionButton>
<UniconsPlus />
<UniconsPlus @click="onAddNewFragment" />
</AppActionButton>
</div>
</div>
Expand Down Expand Up @@ -42,6 +42,10 @@ const name = computed({
)
})
const onAddNewFragment = () => {
snippetStore.addNewFragmentToSnippetsById(snippetStore.selectedId!)
}
emitter.on('focus:snippet-name', () => {
inputRef.value?.select()
})
Expand Down
17 changes: 17 additions & 0 deletions src/renderer/store/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ export const useSnippetStore = defineStore('snippets', {

this.snippet = data.value
store.app.set('selectedSnippetId', this.snippet!.id)
},
async addNewFragmentToSnippetsById (id: string) {
const folderStore = useFolderStore()
const content = [...this.snippet!.content]
const fragmentCount = content.length + 1
const body: Partial<Snippet> = {}

content.push({
label: `Fragment ${fragmentCount}`,
language: folderStore.selected?.defaultLanguage || 'plain_text',
value: ''
})

body.content = content

await this.patchSnippetsById(id, body)
await this.getSnippetsById(id)
}
}
})

0 comments on commit fa1e828

Please sign in to comment.