From fb3284c45bb980b9b86be73caa3a0179fad78203 Mon Sep 17 00:00:00 2001 From: d3m1d0v Date: Wed, 25 Oct 2023 13:10:50 +0300 Subject: [PATCH] feat(CodeBlock): add custom tab key press handling in the codeblock --- .../markdown/CodeBlock/CodeBlockSpecs/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/extensions/markdown/CodeBlock/CodeBlockSpecs/index.ts b/src/extensions/markdown/CodeBlock/CodeBlockSpecs/index.ts index 58861399..f0a7cc64 100644 --- a/src/extensions/markdown/CodeBlock/CodeBlockSpecs/index.ts +++ b/src/extensions/markdown/CodeBlock/CodeBlockSpecs/index.ts @@ -68,6 +68,16 @@ export const CodeBlockSpecs: ExtensionAuto = (builder, op throw new Error('Unexpected toYfm() call on fence node'); }, })); + builder.addKeymap(() => ({ + Tab: (state, dispatch) => { + const {$anchor, $head} = state.selection; + if ($anchor.sameParent($head) && $anchor.parent.type.name === codeBlockNodeName) { + dispatch?.(state.tr.replaceSelectionWith(state.schema.text('\t')).scrollIntoView()); + return true; + } + return false; + }, + })); }; function removeNewLineAtEnd(content: string): string {