diff --git a/app/hooks/useEditorClickHandlers.ts b/app/hooks/useEditorClickHandlers.ts index 822a2e9e8c..5c8f82a9df 100644 --- a/app/hooks/useEditorClickHandlers.ts +++ b/app/hooks/useEditorClickHandlers.ts @@ -5,11 +5,12 @@ import { isModKey } from "~/utils/keyboard"; import { sharedDocumentPath } from "~/utils/routeHelpers"; import { isHash } from "~/utils/urls"; -export default function useEditorClickHandlers({ - shareId, -}: { +type Params = { + /** The share ID of the document being viewed, if any */ shareId?: string; -}) { +}; + +export default function useEditorClickHandlers({ shareId }: Params) { const history = useHistory(); const handleClickLink = React.useCallback( (href: string, event: MouseEvent) => { @@ -39,6 +40,12 @@ export default function useEditorClickHandlers({ return; } + // If we're navigating to a share link from a non-share link then open it in a new tab + if (shareId && navigateTo.startsWith("/s/")) { + window.open(href, "_blank"); + return; + } + // If we're navigating to an internal document link then prepend the // share route to the URL so that the document is loaded in context if (shareId && navigateTo.includes("/doc/")) {