Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/components/inline-tools/inline-tool-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default class LinkInlineTool implements InlineTool {
this.nodes.button.classList.add(this.CSS.button, this.CSS.buttonModifier);

this.nodes.button.innerHTML = IconLink;
this.nodes.button.title = LinkInlineTool.title;

return this.nodes.button;
}
Expand Down Expand Up @@ -172,21 +173,11 @@ export default class LinkInlineTool implements InlineTool {
* Unlink icon pressed
*/
if (parentAnchor) {
/**
* 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();
}
this.selection.expandToTag(parentAnchor);
this.unlink();
this.closeActions();
this.checkState();
this.toolbar.close();

return;
}
Expand All @@ -205,6 +196,7 @@ export default class LinkInlineTool implements InlineTool {
this.nodes.button.innerHTML = IconUnlink;
this.nodes.button.classList.add(this.CSS.buttonUnlink);
this.nodes.button.classList.add(this.CSS.buttonActive);
this.nodes.button.title = 'Unlink';
this.openActions();

/**
Expand All @@ -219,6 +211,7 @@ export default class LinkInlineTool implements InlineTool {
this.nodes.button.innerHTML = IconLink;
this.nodes.button.classList.remove(this.CSS.buttonUnlink);
this.nodes.button.classList.remove(this.CSS.buttonActive);
this.nodes.button.title = 'Link';
}

return !!anchorTag;
Expand All @@ -238,6 +231,13 @@ export default class LinkInlineTool implements InlineTool {
return 'CMD+K';
}

/**
* Returns dynamic title based on whether the current selection is inside a link
*/
public getTitle(): string {
return this.selection.findParentTag('A') ? 'Unlink' : 'Link';
}

/**
* Show/close link input
*/
Expand Down
12 changes: 12 additions & 0 deletions src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,18 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
instance.checkState?.(SelectionUtils.get());
}

/**
* Allow inline tools to provide a dynamic title based on current selection state
*/
const dynamicTitle = (instance as { getTitle?: () => string }).getTitle?.();

if (dynamicTitle !== undefined) {
(popoverItem as PopoverItemHtmlParams).hint = {
...(popoverItem as PopoverItemHtmlParams).hint,
title: dynamicTitle,
};
}

popoverItems.push(popoverItem);
} else if (item.type === PopoverItemType.Html) {
/**
Expand Down
Loading