@@ -139,11 +139,13 @@ export class FlowStructureService {
139
139
}
140
140
141
141
addConnection ( sourceId : string , targetId : string ) : void {
142
- const endLine = this . getEndLineOfSourceElement ( sourceId ) ;
142
+ const sourceNode = this . getSourceNode ( sourceId ) ;
143
143
const target = this . flowStructure . nodes . find (
144
144
( node ) => node . uid == targetId
145
145
) ;
146
146
147
+ const endLine =
148
+ ( sourceNode ?. endLine ?? 0 ) + ( sourceNode ?. isSelfClosing ? 1 : 0 ) ;
147
149
const text = `\t\t\t\t<Forward name="success" path="${ target ?. name } " />\n` ;
148
150
const range = {
149
151
startLineNumber : endLine ,
@@ -152,15 +154,61 @@ export class FlowStructureService {
152
154
endLineNumber : endLine ,
153
155
} ;
154
156
155
- 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
+ }
156
166
}
157
167
158
- getEndLineOfSourceElement ( sourceId : string ) : number {
159
- const currentPipe = this . flowStructure . pipes . find (
168
+ getSourceNode ( sourceId : string ) : FlowStructureNode | undefined {
169
+ return this . flowStructure . pipes . find (
160
170
( pipe : FlowStructureNode ) => pipe . uid === sourceId
161
171
) ;
172
+ }
173
+
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
+ }
182
+ const range = {
183
+ startLineNumber : sourceNode . endLine ,
184
+ startColumn : column ,
185
+ endColumn : sourceNode . column ,
186
+ endLineNumber : sourceNode . endLine ,
187
+ } ;
188
+
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
+ ) ;
198
+ }
162
199
163
- return currentPipe ! . endLine ;
200
+ getClosingTagEditOperation (
201
+ sourceNode : FlowStructureNode
202
+ ) : monaco . editor . ISingleEditOperation {
203
+ const text = `\t\t\t</${ sourceNode . type } >\n` ;
204
+ const range = {
205
+ startLineNumber : sourceNode . endLine + 1 ,
206
+ startColumn : 0 ,
207
+ endColumn : 0 ,
208
+ endLineNumber : sourceNode . endLine + 1 ,
209
+ } ;
210
+
211
+ return { range, text } ;
164
212
}
165
213
166
214
deleteConnection (
@@ -306,7 +354,7 @@ export class FlowStructureService {
306
354
( pipes [ pipes . length - 1 ] ? lastPipe . endLine : lastPipe . line ) + 1 ;
307
355
const pipeName = this . getUniquePipeName ( pipeData . getName ( ) ) ;
308
356
309
- const text = `\t\t\t<${ pipeData . getType ( ) } name="${ pipeName } ">\n\t\t\t</ ${ pipeData . getType ( ) } >\n` ;
357
+ const text = `\t\t\t<${ pipeData . getType ( ) } name="${ pipeName } " / >\n` ;
310
358
const range = {
311
359
startLineNumber : line ,
312
360
startColumn : 0 ,
@@ -744,7 +792,9 @@ export class FlowStructureService {
744
792
parent : FlowStructureNode
745
793
) : void {
746
794
const lastNestedElement = this . findLastNestedElement ( parent ) ;
747
- 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 ) ;
748
798
749
799
const range = lastNestedElement
750
800
? {
@@ -754,13 +804,21 @@ export class FlowStructureService {
754
804
endColumn : 0 ,
755
805
}
756
806
: {
757
- startLineNumber : parent . line + 1 ,
758
- endLineNumber : parent . line + 1 ,
807
+ startLineNumber : endLine ,
808
+ endLineNumber : endLine ,
759
809
startColumn : 0 ,
760
810
endColumn : 0 ,
761
811
} ;
762
812
763
- 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
+ }
764
822
}
765
823
766
824
findLastNestedElement (
0 commit comments