mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-03 19:47:03 +00:00
changes
This commit is contained in:
1 parent
aa44696803
commit
47710970c2
5 files changed
+65
-30
No files matched your search
@@ -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,
|
||||
];
|
||||
@@ -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 });
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user