diff --git a/packages/core/src/api/exporters/html/__snapshots__/mention/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/mention/basic/external.html index e6ba4c7bfc..ac270828c3 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/mention/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/mention/basic/external.html @@ -1 +1 @@ -
I enjoy working with @Matthew
\ No newline at end of file +I enjoy working with @Matthew
diff --git a/packages/core/src/extensions/Blocks/api/inlineContent/createSpec.ts b/packages/core/src/extensions/Blocks/api/inlineContent/createSpec.ts index ca2989c899..3528f080fb 100644 --- a/packages/core/src/extensions/Blocks/api/inlineContent/createSpec.ts +++ b/packages/core/src/extensions/Blocks/api/inlineContent/createSpec.ts @@ -6,6 +6,7 @@ import { Props } from "../blocks/types"; import { StyleSchema } from "../styles/types"; import { addInlineContentAttributes, + addInlineContentKeyboardShortcuts, createInlineContentSpecFromTipTapNode, } from "./internal"; import { @@ -83,6 +84,10 @@ export function createInlineContentSpec< return propsToAttributes(inlineContentConfig.propSchema); }, + addKeyboardShortcuts() { + return addInlineContentKeyboardShortcuts(inlineContentConfig); + }, + parseHTML() { return getInlineContentParseRules(inlineContentConfig); }, diff --git a/packages/core/src/extensions/Blocks/api/inlineContent/internal.ts b/packages/core/src/extensions/Blocks/api/inlineContent/internal.ts index 01f70125c3..1e0106f520 100644 --- a/packages/core/src/extensions/Blocks/api/inlineContent/internal.ts +++ b/packages/core/src/extensions/Blocks/api/inlineContent/internal.ts @@ -1,7 +1,8 @@ -import { Node } from "@tiptap/core"; +import { KeyboardShortcutCommand, Node } from "@tiptap/core"; import { camelToDataKebab } from "../blocks/internal"; -import { Props, PropSchema } from "../blocks/types"; +import { PropSchema, Props } from "../blocks/types"; import { + CustomInlineContentConfig, InlineContentConfig, InlineContentImplementation, InlineContentSchemaFromSpecs, @@ -45,6 +46,27 @@ export function addInlineContentAttributes< return element; } +// see https://github.com/TypeCellOS/BlockNote/pull/435 +export function addInlineContentKeyboardShortcuts< + T extends CustomInlineContentConfig +>( + config: T +): { + [p: string]: KeyboardShortcutCommand; +} { + return { + Backspace: ({ editor }) => { + const resolvedPos = editor.state.selection.$from; + + return ( + editor.state.selection.empty && + resolvedPos.node().type.name === config.type && + resolvedPos.parentOffset === 0 + ); + }, + }; +} + // This helper function helps to instantiate a InlineContentSpec with a // config and implementation that conform to the type of Config export function createInternalInlineContentSpecI enjoy working with @Matthew
\ No newline at end of file +I enjoy working with @Matthew
diff --git a/packages/react/src/test/__snapshots__/mention/basic/internal.html b/packages/react/src/test/__snapshots__/mention/basic/internal.html index fa3e3e8414..b429a68a6f 100644 --- a/packages/react/src/test/__snapshots__/mention/basic/internal.html +++ b/packages/react/src/test/__snapshots__/mention/basic/internal.html @@ -1 +1 @@ -I enjoy working with @Matthew
I enjoy working with @Matthew