🎨 Add multi-select type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8695

This commit is contained in:
Daniel 2023-07-10 11:54:27 +08:00
parent 96e7044baf
commit 2f84aaa4c7
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017

View File

@ -329,6 +329,8 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
newName := data["newName"].(string) newName := data["newName"].(string)
newColor := data["newColor"].(string) newColor := data["newColor"].(string)
// TODO 如果 newName 已经存在
var colIndex int var colIndex int
for i, col := range attrView.Columns { for i, col := range attrView.Columns {
if col.ID != colID { if col.ID != colID {
@ -336,7 +338,14 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
} }
colIndex = i colIndex = i
existOpt := false
for _, opt := range col.Options {
if opt.Name == newName {
existOpt = true
break
}
}
if !existOpt {
for _, opt := range col.Options { for _, opt := range col.Options {
if opt.Name != oldName { if opt.Name != oldName {
continue continue
@ -346,6 +355,7 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
opt.Color = newColor opt.Color = newColor
break break
} }
}
break break
} }
@ -362,6 +372,14 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
break break
} }
} else if nil != cell.Value.MSelect { } else if nil != cell.Value.MSelect {
existInMSelect := false
for _, opt := range cell.Value.MSelect {
if opt.Content == newName {
existInMSelect = true
break
}
}
if !existInMSelect {
for j, opt := range cell.Value.MSelect { for j, opt := range cell.Value.MSelect {
if oldName == opt.Content { if oldName == opt.Content {
cell.Value.MSelect[j].Content = newName cell.Value.MSelect[j].Content = newName
@ -370,6 +388,7 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
} }
} }
} }
}
break break
} }
} }