Skip to content

Commit

Permalink
feat(CodeBlock): add custom tab key press handling in the codeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m1d0v committed Oct 25, 2023
1 parent 67bad99 commit fb3284c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/extensions/markdown/CodeBlock/CodeBlockSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ export const CodeBlockSpecs: ExtensionAuto<CodeBlockSpecsOptions> = (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 {
Expand Down

0 comments on commit fb3284c

Please sign in to comment.