Skip to content

Commit

Permalink
7.2.5 darkmode.0 (#266)
Browse files Browse the repository at this point in the history
* Improve hyperlink onLinkClick option (#255)

Allow Hyperlink onLinkClick to fall back to default handling to reduce redundant code.

* fix autolink bug (#263)

* Filter CTRL+Click for Hyperlink plugin to main button (#262)
  • Loading branch information
Lego6245 authored Mar 8, 2019
1 parent e96d218 commit 0d9e74c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roosterjs",
"version": "7.2.3-darkmode.0",
"version": "7.2.5-darkmode.0",
"description": "Framework-independent javascript editor",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ function hasLinkBeforeCursor(event: PluginKeyboardEvent, editor: Editor): boolea
function autoLink(event: PluginEvent, editor: Editor) {
let anchor = editor.getDocument().createElement('a');
let linkData = cacheGetLinkData(event, editor);

// Need to get searcher before we enter the async callback since the callback can happen when cursor is moved to next line
// and at that time a new searcher won't be able to find the link text to replace
let searcher = editor.getContentSearcherOfCursor();
anchor.textContent = linkData.originalUrl;
anchor.href = linkData.normalizedUrl;

editor.runAsync(() => {
editor.performAutoComplete(() => {
replaceWithNode(editor, linkData.originalUrl, anchor, false /* exactMatch */);
replaceWithNode(editor, linkData.originalUrl, anchor, false /* exactMatch */, searcher);

// The content at cursor has changed. Should also clear the cursor data cache
clearContentSearcherCache(event);
Expand Down
10 changes: 5 additions & 5 deletions packages/roosterjs-editor-plugins/lib/HyperLink/HyperLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export default class HyperLink implements EditorPlugin {
* @param getTooltipCallback A callback function to get tooltip text for an existing hyperlink.
* Default value is to return the href itself. If null, there will be no tooltip text.
* @param target (Optional) Target window name for hyperlink. If null, will use "_blank"
* @param onLinkClick (Optional) Open link callback
* @param onLinkClick (Optional) Open link callback (return false to use default behavior)
*/
constructor(
private getTooltipCallback: (href: string, a: HTMLAnchorElement) => string = href => href,
private target?: string,
private onLinkClick?: (anchor: HTMLAnchorElement, mouseEvent: MouseEvent) => void
private onLinkClick?: (anchor: HTMLAnchorElement, mouseEvent: MouseEvent) => boolean | void
) {}

/**
Expand Down Expand Up @@ -73,16 +73,16 @@ export default class HyperLink implements EditorPlugin {
) as HTMLAnchorElement;

if (anchor) {
if (this.onLinkClick) {
this.onLinkClick(anchor, event.rawEvent);
if (this.onLinkClick && this.onLinkClick(anchor, event.rawEvent) !== false) {
return;
}

let href: string;
if (
!Browser.isFirefox &&
(href = this.tryGetHref(anchor)) &&
(Browser.isMac ? event.rawEvent.metaKey : event.rawEvent.ctrlKey)
(Browser.isMac ? event.rawEvent.metaKey : event.rawEvent.ctrlKey) &&
event.rawEvent.button === 0
) {
try {
const target = this.target || '_blank';
Expand Down

0 comments on commit 0d9e74c

Please sign in to comment.