Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.2.5 darkmode.0 #266

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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