@@ -140,51 +140,66 @@ export class FlowStructureService {
140
140
141
141
addConnection ( sourceId : string , targetId : string ) : void {
142
142
const sourceNode = this . getSourceNode ( sourceId ) ;
143
- if ( ! sourceNode ) {
144
- return ;
145
- }
146
-
147
143
const target = this . flowStructure . nodes . find (
148
144
( node ) => node . uid == targetId
149
145
) ;
150
146
151
- if ( sourceNode . isSelfClosing ) {
152
- this . addClosingBracket ( sourceNode ) ;
153
- this . addClosingTag ( sourceNode ) ;
154
- }
155
- const endline = sourceNode . endLine + ( sourceNode . isSelfClosing ? 1 : 0 ) ;
147
+ const endLine =
148
+ ( sourceNode ?. endLine ?? 0 ) + ( sourceNode ?. isSelfClosing ? 1 : 0 ) ;
156
149
const text = `\t\t\t\t<Forward name="success" path="${ target ?. name } " />\n` ;
157
150
const range = {
158
- startLineNumber : endline ,
151
+ startLineNumber : endLine ,
159
152
startColumn : 0 ,
160
153
endColumn : 0 ,
161
- endLineNumber : endline ,
154
+ endLineNumber : endLine ,
162
155
} ;
163
156
164
- this . monacoEditorComponent ?. applyEdits ( [ { range, text } ] ) ;
157
+ if ( sourceNode ?. isSelfClosing ) {
158
+ this . monacoEditorComponent ?. applyEdits ( [
159
+ this . getClosingBracketEditOperation ( sourceNode ) ,
160
+ { range, text } ,
161
+ this . getClosingTagEditOperation ( sourceNode ) ,
162
+ ] ) ;
163
+ } else {
164
+ this . monacoEditorComponent ?. applyEdits ( [ { range, text } ] ) ;
165
+ }
165
166
}
166
167
167
168
getSourceNode ( sourceId : string ) : FlowStructureNode | undefined {
168
- const sourceNode = this . flowStructure . pipes . find (
169
+ return this . flowStructure . pipes . find (
169
170
( pipe : FlowStructureNode ) => pipe . uid === sourceId
170
171
) ;
171
-
172
- return sourceNode ;
173
172
}
174
173
175
- addClosingBracket ( sourceNode : FlowStructureNode ) : void {
176
- const text = `>\n` ;
174
+ getClosingBracketEditOperation (
175
+ sourceNode : FlowStructureNode
176
+ ) : monaco . editor . ISingleEditOperation {
177
+ const text = `>` ;
178
+ let column = sourceNode . column - 2 ;
179
+ if ( this . hasSpaceBeforeClosingBracket ( sourceNode ) ) {
180
+ column -= 1 ;
181
+ }
177
182
const range = {
178
183
startLineNumber : sourceNode . endLine ,
179
- startColumn : sourceNode . column - 2 ,
184
+ startColumn : column ,
180
185
endColumn : sourceNode . column ,
181
186
endLineNumber : sourceNode . endLine ,
182
187
} ;
183
188
184
- this . monacoEditorComponent ?. applyEdits ( [ { range, text } ] ) ;
189
+ return { range, text } ;
190
+ }
191
+
192
+ hasSpaceBeforeClosingBracket ( sourceNode : FlowStructureNode ) : boolean {
193
+ const lastAttribute = this . findLastAttribute ( sourceNode . attributes ) ;
194
+ return (
195
+ sourceNode . column - ( lastAttribute ?. endColumn ?? 0 ) >= 3 &&
196
+ lastAttribute ?. line === sourceNode . endLine
197
+ ) ;
185
198
}
186
199
187
- addClosingTag ( sourceNode : FlowStructureNode ) : void {
200
+ getClosingTagEditOperation (
201
+ sourceNode : FlowStructureNode
202
+ ) : monaco . editor . ISingleEditOperation {
188
203
const text = `\t\t\t</${ sourceNode . type } >\n` ;
189
204
const range = {
190
205
startLineNumber : sourceNode . endLine + 1 ,
@@ -193,7 +208,7 @@ export class FlowStructureService {
193
208
endLineNumber : sourceNode . endLine + 1 ,
194
209
} ;
195
210
196
- this . monacoEditorComponent ?. applyEdits ( [ { range, text } ] ) ;
211
+ return { range, text } ;
197
212
}
198
213
199
214
deleteConnection (
@@ -777,7 +792,9 @@ export class FlowStructureService {
777
792
parent : FlowStructureNode
778
793
) : void {
779
794
const lastNestedElement = this . findLastNestedElement ( parent ) ;
780
- let text = `\t\t\t\t<${ parameter . type } name="${ parameter . name } ">\n\t\t\t\t</${ parameter . type } >\n` ;
795
+ let text = `\t\t\t\t<${ parameter . type } name="${ parameter . name } " />\n` ;
796
+
797
+ const endLine = parent . endLine + ( parent . isSelfClosing ? 1 : 0 ) ;
781
798
782
799
const range = lastNestedElement
783
800
? {
@@ -787,13 +804,21 @@ export class FlowStructureService {
787
804
endColumn : 0 ,
788
805
}
789
806
: {
790
- startLineNumber : parent . line + 1 ,
791
- endLineNumber : parent . line + 1 ,
807
+ startLineNumber : endLine ,
808
+ endLineNumber : endLine ,
792
809
startColumn : 0 ,
793
810
endColumn : 0 ,
794
811
} ;
795
812
796
- this . monacoEditorComponent ?. applyEdits ( [ { text, range } ] , true ) ;
813
+ if ( parent . isSelfClosing ) {
814
+ this . monacoEditorComponent ?. applyEdits ( [
815
+ this . getClosingBracketEditOperation ( parent ) ,
816
+ { range, text } ,
817
+ this . getClosingTagEditOperation ( parent ) ,
818
+ ] ) ;
819
+ } else {
820
+ this . monacoEditorComponent ?. applyEdits ( [ { range, text } ] ) ;
821
+ }
797
822
}
798
823
799
824
findLastNestedElement (
0 commit comments