fix: Flash of external link decoration when creating doc from selected text

This commit is contained in:
Tom Moor
2022-12-04 17:41:19 -05:00
parent 0a68266365
commit 3d6da26ad6
3 changed files with 10 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { EditorView } from "prosemirror-view";
import * as React from "react";
import createAndInsertLink from "@shared/editor/commands/createAndInsertLink";
import { creatingUrlPrefix } from "@shared/utils/urls";
import { Dictionary } from "~/hooks/useDictionary";
import FloatingToolbar from "./FloatingToolbar";
import LinkEditor, { SearchResult } from "./LinkEditor";
@@ -76,7 +77,7 @@ export default class LinkToolbar extends React.Component<Props> {
return;
}
const href = `creating#${title}`;
const href = `${creatingUrlPrefix}${title}`;
// Insert a placeholder link
dispatch(

View File

@@ -12,6 +12,7 @@ import getRowIndex from "@shared/editor/queries/getRowIndex";
import isMarkActive from "@shared/editor/queries/isMarkActive";
import isNodeActive from "@shared/editor/queries/isNodeActive";
import { MenuItem } from "@shared/editor/types";
import { creatingUrlPrefix } from "@shared/utils/urls";
import { Dictionary } from "~/hooks/useDictionary";
import getDividerMenuItems from "../menus/divider";
import getFormattingMenuItems from "../menus/formatting";
@@ -138,7 +139,7 @@ export default class SelectionToolbar extends React.Component<Props> {
return;
}
const href = `creating#${title}`;
const href = `${creatingUrlPrefix}${title}`;
const markType = state.schema.marks.link;
// Insert a placeholder link

View File

@@ -75,6 +75,11 @@ export function isUrl(text: string, options?: { requireHostname: boolean }) {
}
}
/**
* Temporary prefix applied to links in document that are not yet persisted.
*/
export const creatingUrlPrefix = "creating#";
/**
* Returns true if the given string is a link to outside the application.
*
@@ -82,7 +87,7 @@ export function isUrl(text: string, options?: { requireHostname: boolean }) {
* @returns True if the url is external, false otherwise.
*/
export function isExternalUrl(url: string) {
return !!url && !isInternalUrl(url);
return !!url && !isInternalUrl(url) && !url.startsWith(creatingUrlPrefix);
}
/**