File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -172,21 +172,11 @@ export default class LinkInlineTool implements InlineTool {
172172 * Unlink icon pressed
173173 */
174174 if ( parentAnchor ) {
175- /**
176- * If input is not opened, treat click as explicit unlink action.
177- * If input is opened (e.g., programmatic close when switching tools), avoid unlinking.
178- */
179- if ( ! this . inputOpened ) {
180- this . selection . expandToTag ( parentAnchor ) ;
181- this . unlink ( ) ;
182- this . closeActions ( ) ;
183- this . checkState ( ) ;
184- this . toolbar . close ( ) ;
185- } else {
186- /** Only close actions without clearing saved selection to preserve user state */
187- this . closeActions ( false ) ;
188- this . checkState ( ) ;
189- }
175+ this . selection . expandToTag ( parentAnchor ) ;
176+ this . unlink ( ) ;
177+ this . closeActions ( ) ;
178+ this . checkState ( ) ;
179+ this . toolbar . close ( ) ;
190180
191181 return ;
192182 }
@@ -270,14 +260,16 @@ export default class LinkInlineTool implements InlineTool {
270260 if ( this . selection . isFakeBackgroundEnabled ) {
271261 // if actions is broken by other selection We need to save new selection
272262 const currentSelection = new SelectionUtils ( ) ;
273-
274263 currentSelection . save ( ) ;
275264
276265 this . selection . restore ( ) ;
277266 this . selection . removeFakeBackground ( ) ;
278267
279- // and recover new selection after removing fake background
280- currentSelection . restore ( ) ;
268+ // check if other selection happend
269+ if ( ! currentSelection . savedSelectionRange . collapsed ) {
270+ // and recover new selection after removing fake background
271+ currentSelection . restore ( ) ;
272+ }
281273 }
282274
283275 this . nodes . input . classList . remove ( this . CSS . inputShowed ) ;
Original file line number Diff line number Diff line change @@ -391,6 +391,9 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
391391 onActivate : ( ) => {
392392 this . toolClicked ( instance ) ;
393393 } ,
394+ onClear : ( ) => {
395+ instance ?. clear ?.( ) ;
396+ } ,
394397 hint : {
395398 title : toolTitle ,
396399 description : shortcutBeautified ,
Original file line number Diff line number Diff line change @@ -25,6 +25,21 @@ export abstract class PopoverItem {
2525 }
2626 }
2727
28+ /**
29+ * Calls instance clear function
30+ */
31+ public clear ( ) : void {
32+ if ( this . params === undefined ) {
33+ return ;
34+ }
35+
36+ if ( ! ( 'onClear' in this . params ) ) {
37+ return ;
38+ }
39+
40+ this . params . onClear ?.( this . params ) ;
41+ }
42+
2843 /**
2944 * Destroys the instance
3045 */
Original file line number Diff line number Diff line change @@ -167,9 +167,9 @@ export class PopoverInline extends PopoverDesktop {
167167 if ( item !== this . nestedPopoverTriggerItem ) {
168168 /**
169169 * In case tool had special handling for toggling button (like link tool which modifies selection)
170- * we need to call handleClick on nested popover trigger item
170+ * we need to call clear on nested popover trigger item to restore initial state
171171 */
172- this . nestedPopoverTriggerItem ?. handleClick ( ) ;
172+ this . nestedPopoverTriggerItem ?. clear ( ) ;
173173
174174 /**
175175 * Then close the nested popover
Original file line number Diff line number Diff line change @@ -178,6 +178,13 @@ export interface PopoverItemDefaultBaseParams {
178178 * @param event - event that initiated item activation
179179 */
180180 onActivate : ( item : PopoverItemParams , event ?: PointerEvent ) => void ;
181+
182+ /**
183+ * Popover item clear handler
184+ *
185+ * @param item - item to be cleared
186+ */
187+ onClear : ( item : PopoverItemParams ) => void ;
181188}
182189
183190/**
You can’t perform that action at this time.
0 commit comments