Skip to content

Commit

Permalink
Restore Ctrl+Click behavior on Firefox (#1406)
Browse files Browse the repository at this point in the history
* Remove firefox specific code

* Prevent default

* Fix test
ianeli1 authored Nov 15, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 76a8b5d commit 9917817
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Browser, isCharacterValue, isCtrlOrMetaPressed, matchLink } from 'roosterjs-editor-dom';
import { isCharacterValue, isCtrlOrMetaPressed, matchLink } from 'roosterjs-editor-dom';
import {
DOMEventHandler,
EditorPlugin,
@@ -141,11 +141,11 @@ export default class HyperLink implements EditorPlugin {

let href: string | null;
if (
!Browser.isFirefox &&
(href = this.tryGetHref(anchor)) &&
isCtrlOrMetaPressed(event.rawEvent) &&
event.rawEvent.button === 0
) {
event.rawEvent.preventDefault();
try {
const target = this.target || '_blank';
const window = this.editor?.getDocument().defaultView;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IEditor, PluginEventType } from 'roosterjs-editor-types';
import { Browser } from 'roosterjs-editor-dom';
import { HyperLink } from '../../lib/HyperLink';
import { initEditor } from '../TestHelper';

@@ -68,13 +67,11 @@ describe('HyperLink plugin', () => {
srcElement: anchor,
ctrlKey: true,
button: 0,
preventDefault: () => {},
} as unknown) as MouseEvent,
});
if (Browser.isFirefox) {
expect(openSpy).not.toHaveBeenCalled();
} else {
expect(openSpy).toHaveBeenCalledWith(HREF, '_blank');
}
expect(openSpy).toHaveBeenCalledTimes(1);
expect(openSpy).toHaveBeenCalledWith(HREF, '_blank');
});

it('Does not open the link if its only clicked', () => {

0 comments on commit 9917817

Please sign in to comment.