File tree Expand file tree Collapse file tree
src/components/inline-tools
test/cypress/tests/inline-tools Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Changelog
22
3+ ### 2.31.2
4+
5+ - ` Fix ` - Prevent link removal when applying bold to linked text
6+
37### 2.31.1
48
59- ` Fix ` - Prevent the warning from appearing when ` readOnly ` mode is initially set to ` true `
Original file line number Diff line number Diff line change 11{
22 "name" : " @editorjs/editorjs" ,
3- "version" : " 2.31.1 " ,
3+ "version" : " 2.31.2 " ,
44 "description" : " Editor.js — open source block-style WYSIWYG editor with JSON output" ,
55 "main" : " dist/editorjs.umd.js" ,
66 "module" : " dist/editorjs.mjs" ,
Original file line number Diff line number Diff line change @@ -172,11 +172,21 @@ export default class LinkInlineTool implements InlineTool {
172172 * Unlink icon pressed
173173 */
174174 if ( parentAnchor ) {
175- this . selection . expandToTag ( parentAnchor ) ;
176- this . unlink ( ) ;
177- this . closeActions ( ) ;
178- this . checkState ( ) ;
179- this . toolbar . close ( ) ;
175+ /**
176+ * If input is not opened, treat click as explicit unlink action.
177+ * If input is opened (e.g., programmatic close when switching tools), avoid unlinking.
178+ */
179+ if ( ! this . inputOpened ) {
180+ this . selection . expandToTag ( parentAnchor ) ;
181+ this . unlink ( ) ;
182+ this . closeActions ( ) ;
183+ this . checkState ( ) ;
184+ this . toolbar . close ( ) ;
185+ } else {
186+ /** Only close actions without clearing saved selection to preserve user state */
187+ this . closeActions ( false ) ;
188+ this . checkState ( ) ;
189+ }
180190
181191 return ;
182192 }
Original file line number Diff line number Diff line change @@ -71,4 +71,54 @@ describe('Inline Tool Link', () => {
7171 . find ( '.ce-paragraph span[style]' )
7272 . should ( 'not.exist' ) ;
7373 } ) ;
74+
75+ it ( 'should preserve link when applying bold to linked text' , ( ) => {
76+ cy . createEditor ( {
77+ data : {
78+ blocks : [
79+ {
80+ type : 'paragraph' ,
81+ data : {
82+ text : 'Text with link' ,
83+ } ,
84+ } ,
85+ ] ,
86+ } ,
87+ } ) ;
88+
89+ cy . get ( '[data-cy=editorjs]' )
90+ . find ( '.ce-paragraph' )
91+ . selectText ( 'Text with link' ) ;
92+
93+ cy . get ( '[data-cy=editorjs]' )
94+ . find ( '[data-item-name=link]' )
95+ . click ( ) ;
96+
97+ cy . get ( '[data-cy=editorjs]' )
98+ . find ( '.ce-inline-tool-input' )
99+ . type ( 'https://editorjs.io' )
100+ . type ( '{enter}' ) ;
101+
102+ cy . get ( '[data-cy=editorjs]' )
103+ . find ( 'div.ce-block' )
104+ . find ( 'a' )
105+ . should ( 'have.attr' , 'href' , 'https://editorjs.io' ) ;
106+
107+ cy . get ( '[data-cy=editorjs]' )
108+ . find ( 'div.ce-block' )
109+ . find ( 'a' )
110+ . selectText ( 'Text with link' ) ;
111+
112+ cy . get ( '[data-cy=editorjs]' )
113+ . find ( '[data-item-name=bold]' )
114+ . click ( ) ;
115+
116+ cy . get ( '[data-cy=editorjs]' )
117+ . find ( 'div.ce-block' )
118+ . find ( 'a' )
119+ . should ( 'have.attr' , 'href' , 'https://editorjs.io' )
120+ . find ( 'b' )
121+ . should ( 'exist' )
122+ . should ( 'contain' , 'Text with link' ) ;
123+ } ) ;
74124} ) ;
You can’t perform that action at this time.
0 commit comments