mirror of
https://github.com/codex-team/editor.js
synced 2026-03-14 14:45:47 +01:00
fix(LinkInlineTool): improve unlink behavior based on input state (#2979)
* fix(LinkInlineTool): improve unlink behavior based on input state * 2.31.2-hotfix.0 * fix(linkTool): Add test case to ensure link preservation when applying bold to linked text * Revert "2.31.2-hotfix.0" This reverts commitc68ae54c77. * Add fix entry to changelog * Bump version * Revert "Add fix entry to changelog" This reverts commit7e537d662a. * Add fix entry to changelog without formatting * Refactor test for compatibility with firefox
This commit is contained in:
parent
90d6dec90e
commit
9f942ca72a
4 changed files with 70 additions and 6 deletions
|
|
@ -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`
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,4 +71,54 @@ 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('.ce-paragraph')
|
||||
.selectText('Text with link');
|
||||
|
||||
cy.get('[data-cy=editorjs]')
|
||||
.find('[data-item-name=link]')
|
||||
.click();
|
||||
|
||||
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')
|
||||
.selectText('Text with link');
|
||||
|
||||
cy.get('[data-cy=editorjs]')
|
||||
.find('[data-item-name=bold]')
|
||||
.click();
|
||||
|
||||
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…
Add table
Add a link
Reference in a new issue