@@ -14,7 +14,6 @@ struct TagPopupView: View {
1414 var node : KPNode
1515 @State private var hoveredForClosingTagView : Bool = false
1616 @State private var textForTags : String = " "
17- @State private var previewTag : KPTag ?
1817
1918 @State private var hovered : Bool = false
2019
@@ -51,7 +50,8 @@ struct TagPopupView: View {
5150 . padding ( . horizontal)
5251 }
5352 TextField ( " " , text: $textForTags, onCommit: {
54- addPreviewTag ( )
53+ createTag ( name: textForTags)
54+ textForTags = " "
5555 } )
5656 . padding ( . horizontal)
5757 . foregroundColor ( . black)
@@ -65,41 +65,6 @@ struct TagPopupView: View {
6565
6666
6767 VStack ( alignment: . leading) {
68- if previewTag != nil {
69- HStack ( spacing: 20 ) {
70-
71-
72- //ํ๊ทธ ์์ฑ ๋ฒํผ
73- Button {
74- createTag ( )
75- } label: {
76- Text ( " ์์ฑ " ) . foregroundColor ( . black)
77- } . buttonStyle ( BorderlessButtonStyle ( ) )
78- . padding ( . leading, 10 )
79- . padding ( . top, 10 )
80- . padding ( . bottom, 10 )
81-
82-
83-
84- //ํ๊ทธ ํ๋ฆฌ๋ทฐ
85-
86- Text ( " # \( textForTags) " )
87- . padding ( 8 )
88- . background ( previewTag!. colorTheme. backgroundColor)
89- . cornerRadius ( 6 )
90- . foregroundColor ( . white)
91- . padding ( . top, 10 )
92- . padding ( . bottom, 10 )
93-
94-
95- Spacer ( )
96-
97- } . background ( Color ( hex: 0xF0F0F0 ) )
98- . frame ( width: 234 , height: 40 )
99- . cornerRadius ( 6 )
100- . padding ( 10 )
101- }
102-
10368 if !node. tags. isEmpty {
10469 Text ( " ์ ํ๋ ํ๊ทธ " )
10570 . foregroundColor ( . gray)
@@ -179,25 +144,17 @@ struct TagPopupView: View {
179144 . shadow ( radius: 10 )
180145 }
181146
182- private func addPreviewTag( ) {
183- guard !textForTags. isEmpty else { return }
184- if !document. board. allTags. contains ( where: { $0. name == textForTags } ) {
185- let newTagForPreview = KPTag ( id: UUID ( ) , name: textForTags, colorTheme: KPTagColor . random ( ) )
186- previewTag = newTagForPreview
147+ private func createTag( name: String ) {
148+ if document. board. getTag ( name) == nil {
149+ document. createTag ( name, undoManager: undoManager)
187150 }
188- }
189-
190- private func createTag( ) {
191- guard let previewTag = previewTag else { return }
192151
193- document. createTag ( textForTags, color: previewTag. colorTheme, undoManager: undoManager)
194152 var tags = document. board. getTags ( node. id) . map { $0. id }
195- guard let createdTag = document. board. getTag ( textForTags) ? . id else { return }
196- tags. append ( createdTag)
197-
198- document. updateNode ( node. id, tags: tags, undoManager: undoManager)
199- self . previewTag = nil
200- self . textForTags = " "
153+ guard let createdTag = document. board. getTag ( name) ? . id else { return }
154+ if !tags. contains ( where: { $0 == createdTag } ) {
155+ tags. append ( createdTag)
156+ document. updateNode ( node. id, tags: tags, undoManager: undoManager)
157+ }
201158 }
202159}
203160
0 commit comments