Skip to content

Commit a89f3d0

Browse files
authored
Fix link tool interaction with other tools (#2977)
* fix(selection): removeFakeBackground no longer removes text formatting * fix(selection): fix jsdoc * fix(linkTool): add test case to ensure text formatting preservation when applying link * Add fix entry to changelog * bump version
1 parent cc624ca commit a89f3d0

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 2.31.3
4+
5+
- `Fix` - Prevent text formatting removal when applying link
6+
37
### 2.31.2
48

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/editorjs",
3-
"version": "2.31.2",
3+
"version": "2.31.3",
44
"description": "Editor.js — open source block-style WYSIWYG editor with JSON output",
55
"main": "dist/editorjs.umd.js",
66
"module": "dist/editorjs.mjs",

src/components/selection.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ export default class SelectionUtils {
5757
public isFakeBackgroundEnabled = false;
5858

5959
/**
60-
* Native Document's commands for fake background
60+
* Native Document's command for fake background
6161
*/
6262
private readonly commandBackground: string = 'backColor';
63-
private readonly commandRemoveFormat: string = 'removeFormat';
6463

6564
/**
6665
* Editor styles
@@ -416,9 +415,9 @@ export default class SelectionUtils {
416415
if (!this.isFakeBackgroundEnabled) {
417416
return;
418417
}
418+
document.execCommand(this.commandBackground, false, 'transparent');
419419

420420
this.isFakeBackgroundEnabled = false;
421-
document.execCommand(this.commandRemoveFormat);
422421
}
423422

424423
/**

test/cypress/tests/inline-tools/link.cy.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,75 @@ describe('Inline Tool Link', () => {
121121
.should('exist')
122122
.should('contain', 'Text with link');
123123
});
124+
125+
it('should preserve bold and italic when applying link', () => {
126+
cy.createEditor({
127+
data: {
128+
blocks: [
129+
{
130+
type: 'paragraph',
131+
data: {
132+
text: 'Bold and italic text',
133+
},
134+
},
135+
],
136+
},
137+
});
138+
139+
cy.get('[data-cy=editorjs]')
140+
.find('.ce-paragraph')
141+
.selectText('Bold and italic text');
142+
143+
cy.get('[data-cy=editorjs]')
144+
.find('[data-item-name=bold]')
145+
.click();
146+
147+
cy.get('[data-cy=editorjs]')
148+
.find('div.ce-block')
149+
.find('b')
150+
.should('exist')
151+
.should('contain', 'Bold and italic text');
152+
153+
cy.get('[data-cy=editorjs]')
154+
.find('div.ce-block')
155+
.find('b')
156+
.selectText('Bold and italic text');
157+
158+
cy.get('[data-cy=editorjs]')
159+
.find('[data-item-name=italic]')
160+
.click();
161+
162+
cy.get('[data-cy=editorjs]')
163+
.find('div.ce-block')
164+
.find('b')
165+
.should('exist')
166+
.find('i')
167+
.should('exist')
168+
.should('contain', 'Bold and italic text');
169+
170+
cy.get('[data-cy=editorjs]')
171+
.find('div.ce-block')
172+
.find('b')
173+
.find('i')
174+
.selectText('Bold and italic text');
175+
176+
cy.get('[data-cy=editorjs]')
177+
.find('[data-item-name=link]')
178+
.click();
179+
180+
cy.get('[data-cy=editorjs]')
181+
.find('.ce-inline-tool-input')
182+
.type('https://editorjs.io')
183+
.type('{enter}');
184+
185+
cy.get('[data-cy=editorjs]')
186+
.find('div.ce-block')
187+
.find('b')
188+
.should('exist')
189+
.find('i')
190+
.should('exist')
191+
.find('a')
192+
.should('have.attr', 'href', 'https://editorjs.io')
193+
.should('contain', 'Bold and italic text');
194+
});
124195
});

0 commit comments

Comments
 (0)