This commit is contained in:
pj committed 2026-06-21 14:17:57 -04:00
1 parent aa44696803
commit 47710970c2
5 files changed
+65 -30

No files matched your search

+2
View File
@@ -2,6 +2,7 @@ import type { Extensions } from "@tiptap/core";
import StarterKit from "@tiptap/starter-kit";
import Placeholder from "@tiptap/extension-placeholder";
import { Figure } from "./figure";
import { ParagraphIndent } from "./indent";
export const editorExtensions: Extensions = [
StarterKit.configure({
@@ -13,4 +14,5 @@ export const editorExtensions: Extensions = [
placeholder: ({ node }) => (node.type.name === "heading" ? "" : "Begin your chapter…"),
}),
Figure,
ParagraphIndent,
];
+42
View File
@@ -0,0 +1,42 @@
import { Extension } from "@tiptap/core";
export const ParagraphIndent = Extension.create({
name: "paragraphIndent",
addGlobalAttributes() {
return [
{
types: ["paragraph"],
attributes: {
indent: {
default: false,
keepOnSplit: false,
parseHTML: (el) => el.getAttribute("data-indent") === "true",
renderHTML: (attrs) => (attrs.indent ? { "data-indent": "true" } : {}),
},
},
},
];
},
addKeyboardShortcuts() {
return {
Tab: () => {
if (this.editor.isActive("listItem")) return false;
this.editor.commands.updateAttributes("paragraph", { indent: true });
return true;
},
"Shift-Tab": () => {
if (this.editor.isActive("listItem")) return false;
this.editor.commands.updateAttributes("paragraph", { indent: false });
return true;
},
Backspace: () => {
const { $from, empty } = this.editor.state.selection;
if (!empty || $from.parentOffset !== 0) return false;
if ($from.parent.type.name !== "paragraph" || !$from.parent.attrs.indent) return false;
return this.editor.commands.updateAttributes("paragraph", { indent: false });
},
};
},
});