diff --git a/app/editor/index.tsx b/app/editor/index.tsx index 8713764ab..327f9c28f 100644 --- a/app/editor/index.tsx +++ b/app/editor/index.tsx @@ -101,8 +101,6 @@ export type Props = { ) => void; /** Callback when user hovers on any link in the document */ onHoverLink?: (event: MouseEvent) => boolean; - /** Callback when user clicks on any hashtag in the document */ - onClickHashtag?: (tag: string, event: MouseEvent) => void; /** Callback when user presses any key with document focused */ onKeyDown?: (event: React.KeyboardEvent) => void; /** Collection of embed types to render in the document */ diff --git a/app/scenes/KeyboardShortcuts.tsx b/app/scenes/KeyboardShortcuts.tsx index 248fd8030..02273e975 100644 --- a/app/scenes/KeyboardShortcuts.tsx +++ b/app/scenes/KeyboardShortcuts.tsx @@ -84,7 +84,7 @@ function KeyboardShortcuts() { {metaDisplay} + Enter ), - label: t("Save document and exit"), + label: t("Go to link"), }, { shortcut: ( diff --git a/shared/editor/marks/Link.tsx b/shared/editor/marks/Link.tsx index 0fa6e2ead..7f89e1fbd 100644 --- a/shared/editor/marks/Link.tsx +++ b/shared/editor/marks/Link.tsx @@ -15,6 +15,8 @@ import * as React from "react"; import ReactDOM from "react-dom"; import { isExternalUrl, sanitizeUrl } from "../../utils/urls"; import findLinkNodes from "../queries/findLinkNodes"; +import getMarkRange from "../queries/getMarkRange"; +import isMarkActive from "../queries/isMarkActive"; import { EventType, Dispatch } from "../types"; import Mark from "./Mark"; @@ -121,6 +123,26 @@ export default class Link extends Mark { return toggleMark(type, { href: "" })(state, dispatch); }, + "Mod-Enter": (state: EditorState) => { + if (isMarkActive(type)(state)) { + const range = getMarkRange( + state.selection.$from, + state.schema.marks.link + ); + if (range && range.mark && this.options.onClickLink) { + try { + const event = new KeyboardEvent("keydown", { metaKey: false }); + this.options.onClickLink(range.mark.attrs.href, event); + } catch (err) { + this.editor.props.onShowToast( + this.options.dictionary.openLinkError + ); + } + return true; + } + } + return false; + }, }; } @@ -198,13 +220,6 @@ export default class Link extends Mark { : ""); try { - const isHashtag = href.startsWith("#"); - if (isHashtag && this.options.onClickHashtag) { - event.stopPropagation(); - event.preventDefault(); - this.options.onClickHashtag(href, event); - } - if (this.options.onClickLink) { event.stopPropagation(); event.preventDefault(); diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index bac7fdbf3..3582ba2ce 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -520,7 +520,6 @@ "Toggle navigation": "Toggle navigation", "Focus search input": "Focus search input", "Open this guide": "Open this guide", - "Save document and exit": "Save document and exit", "Publish document and exit": "Publish document and exit", "Save document": "Save document", "Cancel editing": "Cancel editing",