diff options
author | Bob Zeleznik <zzzman@gmail.com> | 2019-12-10 19:35:08 -0500 |
---|---|---|
committer | Bob Zeleznik <zzzman@gmail.com> | 2019-12-10 19:35:08 -0500 |
commit | ca70b29bbb1818764b98196f8c28a1255a17965c (patch) | |
tree | 116cacbef2d09a4b010ce97eeb32002e33a59785 /src | |
parent | 68ad65580e5d01e4d47f2573972f908b7f403c17 (diff) |
added %q to indent paragraphs
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/ParagraphNodeSpec.ts | 6 | ||||
-rw-r--r-- | src/client/util/RichTextRules.ts | 14 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/client/util/ParagraphNodeSpec.ts b/src/client/util/ParagraphNodeSpec.ts index fceb8c00f..0a3b68217 100644 --- a/src/client/util/ParagraphNodeSpec.ts +++ b/src/client/util/ParagraphNodeSpec.ts @@ -34,6 +34,7 @@ const ParagraphNodeSpec: NodeSpec = { color: { default: null }, id: { default: null }, indent: { default: null }, + inset: { default: null }, lineSpacing: { default: null }, // TODO: Add UI to let user edit / clear padding. paddingBottom: { default: null }, @@ -76,6 +77,7 @@ function toDOM(node: Node): DOMOutputSpec { const { align, indent, + inset, lineSpacing, paddingTop, paddingBottom, @@ -109,6 +111,10 @@ function toDOM(node: Node): DOMOutputSpec { style += `text-indent: ${indent}; padding-left: ${indent < 0 ? -indent : undefined};`; } + if (inset) { + style += `margin-left: ${inset}; margin-right: ${inset};`; + } + style && (attrs.style = style); if (indent) { diff --git a/src/client/util/RichTextRules.ts b/src/client/util/RichTextRules.ts index 5f2d67a3e..94bfc5ef2 100644 --- a/src/client/util/RichTextRules.ts +++ b/src/client/util/RichTextRules.ts @@ -143,6 +143,20 @@ export const inpRules = { return null; }), new InputRule( + new RegExp(/q$/), + (state, match, start, end) => { + if (state.selection.to === state.selection.from) return null; + const pos = (state.doc.resolve(start) as any); + let depth = pos.path.length / 3 - 1; + for (; depth >= 0; depth--) { + if (pos.node(depth).type === schema.nodes.paragraph) { + const replaced = state.tr.setNodeMarkup(pos.pos - pos.parentOffset - 1, pos.node(depth).type, { ...pos.node(depth).attrs, inset: 30 }); + return replaced.setSelection(new TextSelection(replaced.doc.resolve(end - 2))); + } + } + return null; + }), + new InputRule( new RegExp(/!$/), (state, match, start, end) => { if (state.selection.to === state.selection.from && !(state as any).EnteringStyle) return null; |