Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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.5

- `Fix` - Handle __Ctrl + click__ on links with inline styles applied (e.g., bold, italic)

### 2.31.4

- `Fix` - Prevent inline-toolbar re-renders when linked text is selected
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.4",
"version": "2.31.5",
"description": "Editor.js — open source block-style WYSIWYG editor with JSON output",
"main": "dist/editorjs.umd.js",
"module": "dist/editorjs.mjs",
Expand Down
10 changes: 10 additions & 0 deletions src/components/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,16 @@ export default class Dom {
return element.tagName.toLowerCase() === 'a';
}

/**
* Returns the closest ancestor anchor (A tag) of the given element (including itself)
*
* @param element - element to check
* @returns {HTMLAnchorElement | null}
*/
public static getAnchor(element: Element): HTMLAnchorElement | null {
return element.closest("a");
}

/**
* Return element's offset related to the document
*
Expand Down
7 changes: 4 additions & 3 deletions src/components/modules/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,12 +773,13 @@ export default class UI extends Module<UINodes> {
*/
const element = event.target as Element;
const ctrlKey = event.metaKey || event.ctrlKey;

if ($.isAnchor(element) && ctrlKey) {
const anchor = $.getAnchor(element);

if (anchor && ctrlKey) {
event.stopImmediatePropagation();
event.stopPropagation();

const href = element.getAttribute('href');
const href = anchor.getAttribute('href');
const validUrl = _.getValidUrl(href);

_.openTab(validUrl);
Expand Down
46 changes: 46 additions & 0 deletions test/cypress/tests/inline-tools/link.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,50 @@ describe('Inline Tool Link', () => {
.should('have.attr', 'href', 'https://editorjs.io')
.should('contain', 'Bold and italic text');
});

it('should open formatted link in the same tab', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test name is not clearly describes the case you just fixed

cy.createEditor({
data: {
blocks: [
{
type: 'paragraph',
data: {
text: 'Link text',
},
},
],
},
});

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

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

cy.get('[data-cy=editorjs]')
.find('.ce-inline-tool-input')
.type('https://test.io/')
.type('{enter}');

cy.get('[data-cy=editorjs]')
.find('div.ce-block')
.find('a')
.selectText('Link text');

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

cy.window().then((win) => {
cy.stub(win, 'open').as('windowOpen');
});

cy.contains('[data-cy=editorjs] div.ce-block i', 'Link text')
.click({ ctrlKey: true });

cy.get('@windowOpen').should('be.calledWith', 'https://test.io/');
});
});
Loading