🎨 支持通过界面设置代码片段 https://github.com/siyuan-note/siyuan/issues/6357

This commit is contained in:
Liang Ding 2022-10-27 20:03:02 +08:00
parent 8f942aa631
commit dd30521f72
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 19 additions and 33 deletions

View file

@ -50,32 +50,10 @@ func RemoveSnippet(id string) (ret *conf.Snippet, err error) {
return
}
func SetSnippet(id, name, typ, content string, enabled bool) (ret *conf.Snippet, err error) {
func SetSnippet(snippets []*conf.Snippet) (err error) {
snippetsLock.Lock()
defer snippetsLock.Unlock()
snippets, err := loadSnippets()
if nil != err {
return
}
isUpdate := false
for _, s := range snippets {
if s.ID == id {
s.Name = name
s.Type = typ
s.Content = content
s.Enabled = enabled
ret = s
isUpdate = true
break
}
}
if !isUpdate {
ret = &conf.Snippet{ID: id, Name: name, Type: typ, Content: content, Enabled: enabled}
snippets = append(snippets, ret)
}
err = writeSnippetsConf(snippets)
return
}