File tree Expand file tree Collapse file tree
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.5
4+
5+ - ` Fix ` - Handle __ Ctrl + click__ on links with inline styles applied (e.g., bold, italic)
6+
37### 2.31.4
48
59- ` Fix ` - Prevent inline-toolbar re-renders when linked text is selected
Original file line number Diff line number Diff line change 11{
22 "name" : " @editorjs/editorjs" ,
3- "version" : " 2.31.4 " ,
3+ "version" : " 2.31.5 " ,
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 @@ -566,6 +566,16 @@ export default class Dom {
566566 return element . tagName . toLowerCase ( ) === 'a' ;
567567 }
568568
569+ /**
570+ * Returns the closest ancestor anchor (A tag) of the given element (including itself)
571+ *
572+ * @param element - element to check
573+ * @returns {HTMLAnchorElement | null }
574+ */
575+ public static getClosestAnchor ( element : Element ) : HTMLAnchorElement | null {
576+ return element . closest ( "a" ) ;
577+ }
578+
569579 /**
570580 * Return element's offset related to the document
571581 *
Original file line number Diff line number Diff line change @@ -773,12 +773,13 @@ export default class UI extends Module<UINodes> {
773773 */
774774 const element = event . target as Element ;
775775 const ctrlKey = event . metaKey || event . ctrlKey ;
776-
777- if ( $ . isAnchor ( element ) && ctrlKey ) {
776+ const anchor = $ . getClosestAnchor ( element ) ;
777+
778+ if ( anchor && ctrlKey ) {
778779 event . stopImmediatePropagation ( ) ;
779780 event . stopPropagation ( ) ;
780781
781- const href = element . getAttribute ( 'href' ) ;
782+ const href = anchor . getAttribute ( 'href' ) ;
782783 const validUrl = _ . getValidUrl ( href ) ;
783784
784785 _ . openTab ( validUrl ) ;
Original file line number Diff line number Diff line change @@ -192,4 +192,50 @@ describe('Inline Tool Link', () => {
192192 . should ( 'have.attr' , 'href' , 'https://editorjs.io' )
193193 . should ( 'contain' , 'Bold and italic text' ) ;
194194 } ) ;
195+
196+ it ( 'should open a link if it is wrapped in another formatting' , ( ) => {
197+ cy . createEditor ( {
198+ data : {
199+ blocks : [
200+ {
201+ type : 'paragraph' ,
202+ data : {
203+ text : 'Link text' ,
204+ } ,
205+ } ,
206+ ] ,
207+ } ,
208+ } ) ;
209+
210+ cy . get ( '[data-cy=editorjs]' )
211+ . find ( '.ce-paragraph' )
212+ . selectText ( 'Link text' ) ;
213+
214+ cy . get ( '[data-cy=editorjs]' )
215+ . find ( '[data-item-name=link]' )
216+ . click ( ) ;
217+
218+ cy . get ( '[data-cy=editorjs]' )
219+ . find ( '.ce-inline-tool-input' )
220+ . type ( 'https://test.io/' )
221+ . type ( '{enter}' ) ;
222+
223+ cy . get ( '[data-cy=editorjs]' )
224+ . find ( 'div.ce-block' )
225+ . find ( 'a' )
226+ . selectText ( 'Link text' ) ;
227+
228+ cy . get ( '[data-cy=editorjs]' )
229+ . find ( '[data-item-name=italic]' )
230+ . click ( ) ;
231+
232+ cy . window ( ) . then ( ( win ) => {
233+ cy . stub ( win , 'open' ) . as ( 'windowOpen' ) ;
234+ } ) ;
235+
236+ cy . contains ( '[data-cy=editorjs] div.ce-block i' , 'Link text' )
237+ . click ( { ctrlKey : true } ) ;
238+
239+ cy . get ( '@windowOpen' ) . should ( 'be.calledWith' , 'https://test.io/' ) ;
240+ } ) ;
195241} ) ;
You can’t perform that action at this time.
0 commit comments