@@ -19,6 +19,7 @@ class IbexaCustomTagUI extends Plugin {
1919 this . addCustomTag = this . addCustomTag . bind ( this ) ;
2020
2121 this . isNew = false ;
22+ this . activeModelElement = null ;
2223
2324 let timeoutId = null ;
2425 this . listenTo ( this . balloon . view , 'change:top' , ( ) => {
@@ -95,8 +96,7 @@ class IbexaCustomTagUI extends Plugin {
9596 const formView = new IbexaCustomTagFormView ( { locale : this . editor . locale } ) ;
9697
9798 this . listenTo ( formView , 'save-custom-tag' , ( ) => {
98- const modelElement = this . editor . model . document . selection . getSelectedElement ( ) ;
99- const values = modelElement . getAttribute ( 'values' ) ;
99+ const values = this . activeModelElement . getAttribute ( 'values' ) ;
100100 const newValues = { ...values } ;
101101
102102 this . isNew = false ;
@@ -112,7 +112,7 @@ class IbexaCustomTagUI extends Plugin {
112112 } ) ;
113113
114114 this . editor . model . change ( ( writer ) => {
115- writer . setAttribute ( 'values' , newValues , modelElement ) ;
115+ writer . setAttribute ( 'values' , newValues , this . activeModelElement ) ;
116116 } ) ;
117117
118118 this . reinitAttributesView ( ) ;
@@ -151,8 +151,9 @@ class IbexaCustomTagUI extends Plugin {
151151 }
152152
153153 showForm ( ) {
154- const modelElement = this . editor . model . document . selection . getSelectedElement ( ) ;
155- const values = modelElement . getAttribute ( 'values' ) ;
154+ this . activeModelElement = this . editor . model . document . selection . getSelectedElement ( ) ;
155+
156+ const values = this . activeModelElement . getAttribute ( 'values' ) ;
156157 const parsedValues = Object . entries ( values ) . reduce ( ( output , [ key , value ] ) => {
157158 if ( this . config . attributes [ key ] ?. type === 'boolean' ) {
158159 return {
@@ -189,14 +190,14 @@ class IbexaCustomTagUI extends Plugin {
189190 }
190191
191192 removeCustomTag ( ) {
192- const modelElement = this . editor . model . document . selection . getSelectedElement ( ) ;
193-
194193 this . editor . model . change ( ( writer ) => {
195194 if ( this . balloon . hasView ( this . attributesView ) ) {
196195 this . hideAttributes ( ) ;
197196 }
198197
199- writer . remove ( modelElement ) ;
198+ writer . remove ( this . activeModelElement ) ;
199+
200+ this . activeModelElement = null ;
200201 } ) ;
201202 }
202203
@@ -209,13 +210,16 @@ class IbexaCustomTagUI extends Plugin {
209210 }
210211
211212 addCustomTag ( ) {
213+ if ( this . balloon . hasView ( this . formView ) ) {
214+ return ;
215+ }
216+
212217 const values = Object . entries ( this . config . attributes ) . reduce ( ( outputValues , [ attributeName , config ] ) => {
213218 outputValues [ attributeName ] = config . defaultValue ;
214219
215220 return outputValues ;
216221 } , { } ) ;
217222
218- this . editor . focus ( ) ;
219223 this . editor . execute ( 'insertIbexaCustomTag' , { customTagName : this . componentName , values } ) ;
220224
221225 if ( this . hasAttributes ( ) ) {
0 commit comments