fix: Flash of external link decoration when creating doc from selected text
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user