mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 支持通过界面设置代码片段 https://github.com/siyuan-note/siyuan/issues/6357
This commit is contained in:
parent
8f942aa631
commit
dd30521f72
2 changed files with 19 additions and 33 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue