Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 2.31.2

- `Fix` - Prevent link removal when applying bold to linked text

### 2.31.1

- `Fix` - Prevent the warning from appearing when `readOnly` mode is initially set to `true`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/editorjs",
"version": "2.31.1",
"version": "2.31.2",
"description": "Editor.js — open source block-style WYSIWYG editor with JSON output",
"main": "dist/editorjs.umd.js",
"module": "dist/editorjs.mjs",
Expand Down
20 changes: 15 additions & 5 deletions src/components/inline-tools/inline-tool-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
48 changes: 48 additions & 0 deletions test/cypress/tests/inline-tools/link.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,52 @@ describe('Inline Tool Link', () => {
.find('.ce-paragraph span[style]')
.should('not.exist');
});

it('should preserve link when applying bold to linked text', () => {
cy.createEditor({
data: {
blocks: [
{
type: 'paragraph',
data: {
text: 'Text with link',
},
},
],
},
});

cy.get('[data-cy=editorjs]')
.find('div.ce-block')
.click()
.type('{selectall}')
.wait(200)
.type('{ctrl}K');

cy.get('[data-cy=editorjs]')
.find('.ce-inline-tool-input')
.type('https://editorjs.io')
.type('{enter}');

cy.get('[data-cy=editorjs]')
.find('div.ce-block')
.find('a')
.should('have.attr', 'href', 'https://editorjs.io');

cy.get('[data-cy=editorjs]')
.find('div.ce-block')
.find('a')
.click()
.type('{selectall}')
.wait(200)
.type('{ctrl}B');

cy.get('[data-cy=editorjs]')
.find('div.ce-block')
.find('a')
.should('have.attr', 'href', 'https://editorjs.io')
.find('b')
.should('exist')
.should('contain', 'Text with link');
});
});
Loading