aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/RichTextRules.ts
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-12-09 16:39:32 -0500
committerbob <bcz@cs.brown.edu>2019-12-09 16:39:32 -0500
commit27df91d19d7720bbd143f3f447807bfae583d5df (patch)
tree6186045bd7c0823bc3efb0bb7038ea0cf54a7d0a /src/client/util/RichTextRules.ts
parentc9c91b0e74934e36514916786da8822b1f3c05f3 (diff)
added preliminary support for paragraph indenting and hanging indents.
Diffstat (limited to 'src/client/util/RichTextRules.ts')
-rw-r--r--src/client/util/RichTextRules.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/client/util/RichTextRules.ts b/src/client/util/RichTextRules.ts
index c9414fb0b..4e60976d5 100644
--- a/src/client/util/RichTextRules.ts
+++ b/src/client/util/RichTextRules.ts
@@ -115,6 +115,34 @@ export const inpRules = {
return node ? state.tr.addMark(start, end, schema.marks.user_tag.create({ userid: Doc.CurrentUserEmail, tag: "ignore", modified: Math.round(Date.now() / 1000 / 60) })) : state.tr;
}),
new InputRule(
+ new RegExp(/d$/),
+ (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, indent: 25 });
+ return replaced.setSelection(new TextSelection(replaced.doc.resolve(end - 2)));
+ }
+ }
+ return null;
+ }),
+ new InputRule(
+ new RegExp(/h$/),
+ (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, indent: -25 });
+ 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;