Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: use single input rule for heading

Abdullah Atta62c4fb328c0c
diff --git a/packages/editor/src/extensions/heading/heading.ts b/packages/editor/src/extensions/heading/heading.ts
index e973324ad..27860f20c 100644
--- a/packages/editor/src/extensions/heading/heading.ts
+++ b/packages/editor/src/extensions/heading/heading.ts
@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { textblockTypeInputRule } from "@tiptap/core";
import { Heading as TiptapHeading } from "@tiptap/extension-heading";
+const HEADING_REGEX = /^(#{1,6})\s$/;
export const Heading = TiptapHeading.extend({
addCommands() {
return {
@@ -56,16 +57,17 @@ export const Heading = TiptapHeading.extend({
},
addInputRules() {
- return this.options.levels.map((level) => {
- return textblockTypeInputRule({
- find: new RegExp(`^(#{1,${level}})\\s$`),
+ return [
+ textblockTypeInputRule({
+ find: HEADING_REGEX,
type: this.type,
- getAttributes: () => {
+ getAttributes: (match) => {
const { textAlign, textDirection } =
- this.editor.state.selection.$from.parent.attrs;
+ this.editor.state.selection.$from.parent?.attrs || {};
+ const level = match[1].length;
return { level, textAlign, textDirection };
}
- });
- });
+ })
+ ];
}
});