From 3a5014f1165a7a80c240182e85b63a8496410bf7 Mon Sep 17 00:00:00 2001 From: Alex Gaillard Date: Wed, 21 Jan 2026 12:37:15 -0500 Subject: [PATCH] fix(LinkInlineTool): improve unlink behavior based on input state --- .../inline-tools/inline-tool-link.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/inline-tools/inline-tool-link.ts b/src/components/inline-tools/inline-tool-link.ts index 9b413a564..999a30c4c 100644 --- a/src/components/inline-tools/inline-tool-link.ts +++ b/src/components/inline-tools/inline-tool-link.ts @@ -172,11 +172,21 @@ export default class LinkInlineTool implements InlineTool { * Unlink icon pressed */ if (parentAnchor) { - this.selection.expandToTag(parentAnchor); - this.unlink(); - this.closeActions(); - this.checkState(); - this.toolbar.close(); + /** + * If input is not opened, treat click as explicit unlink action. + * If input is opened (e.g., programmatic close when switching tools), avoid unlinking. + */ + if (!this.inputOpened) { + this.selection.expandToTag(parentAnchor); + this.unlink(); + this.closeActions(); + this.checkState(); + this.toolbar.close(); + } else { + /** Only close actions without clearing saved selection to preserve user state */ + this.closeActions(false); + this.checkState(); + } return; }