Skip to content
Merged
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
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.3

- `Fix` - Prevent text formatting removal when applying link

### 2.31.2

- `Fix` - Prevent link removal when applying bold to linked text
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.2",
"version": "2.31.3",
"description": "Editor.js — open source block-style WYSIWYG editor with JSON output",
"main": "dist/editorjs.umd.js",
"module": "dist/editorjs.mjs",
Expand Down
5 changes: 2 additions & 3 deletions src/components/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ export default class SelectionUtils {
public isFakeBackgroundEnabled = false;

/**
* Native Document's commands for fake background
* Native Document's command for fake background
*/
private readonly commandBackground: string = 'backColor';
private readonly commandRemoveFormat: string = 'removeFormat';

/**
* Editor styles
Expand Down Expand Up @@ -416,9 +415,9 @@ export default class SelectionUtils {
if (!this.isFakeBackgroundEnabled) {
return;
}
document.execCommand(this.commandBackground, false, 'transparent');

this.isFakeBackgroundEnabled = false;
document.execCommand(this.commandRemoveFormat);
}

/**
Expand Down
71 changes: 71 additions & 0 deletions test/cypress/tests/inline-tools/link.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,75 @@ describe('Inline Tool Link', () => {
.should('exist')
.should('contain', 'Text with link');
});

it('should preserve bold and italic when applying link', () => {
cy.createEditor({
data: {
blocks: [
{
type: 'paragraph',
data: {
text: 'Bold and italic text',
},
},
],
},
});

cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.selectText('Bold and italic text');

cy.get('[data-cy=editorjs]')
.find('[data-item-name=bold]')
.click();

cy.get('[data-cy=editorjs]')
.find('div.ce-block')
.find('b')
.should('exist')
.should('contain', 'Bold and italic text');

cy.get('[data-cy=editorjs]')
.find('div.ce-block')
.find('b')
.selectText('Bold and italic text');

cy.get('[data-cy=editorjs]')
.find('[data-item-name=italic]')
.click();

cy.get('[data-cy=editorjs]')
.find('div.ce-block')
.find('b')
.should('exist')
.find('i')
.should('exist')
.should('contain', 'Bold and italic text');

cy.get('[data-cy=editorjs]')
.find('div.ce-block')
.find('b')
.find('i')
.selectText('Bold and italic text');

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('b')
.should('exist')
.find('i')
.should('exist')
.find('a')
.should('have.attr', 'href', 'https://editorjs.io')
.should('contain', 'Bold and italic text');
});
});
Loading