@@ -17,6 +17,7 @@ export default class FormEditorActions extends EditorActions {
17
17
_registerDefaultActions ( injector ) {
18
18
const commandStack = injector . get ( 'commandStack' , false ) ,
19
19
formFieldRegistry = injector . get ( 'formFieldRegistry' , false ) ,
20
+ modeling = injector . get ( 'modeling' , false ) ,
20
21
selection = injector . get ( 'selection' , false ) ;
21
22
22
23
if ( commandStack ) {
@@ -48,11 +49,45 @@ export default class FormEditorActions extends EditorActions {
48
49
selection . set ( formField ) ;
49
50
}
50
51
} ) ;
52
+
53
+ }
54
+
55
+ if ( modeling && selection ) {
56
+
57
+ // @ts -ignore
58
+ this . register ( 'removeSelection' , ( ) => {
59
+ const selectedFormField = selection . get ( ) ;
60
+
61
+ if ( ! selectedFormField ) {
62
+ return ;
63
+ }
64
+
65
+ const parentField = formFieldRegistry . get ( selectedFormField . _parent ) ;
66
+
67
+ const index = getFormFieldIndex ( parentField , selectedFormField ) ;
68
+
69
+ modeling . removeFormField ( selectedFormField , parentField , index ) ;
70
+ } ) ;
51
71
}
52
72
}
53
73
}
54
74
55
75
FormEditorActions . $inject = [
56
76
'eventBus' ,
57
77
'injector'
58
- ] ;
78
+ ] ;
79
+
80
+
81
+ // helper ////////////
82
+
83
+ function getFormFieldIndex ( parent , formField ) {
84
+ let fieldFormIndex = parent . components . length ;
85
+
86
+ parent . components . forEach ( ( { id } , index ) => {
87
+ if ( id === formField . id ) {
88
+ fieldFormIndex = index ;
89
+ }
90
+ } ) ;
91
+
92
+ return fieldFormIndex ;
93
+ }
0 commit comments