diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2019-12-10 20:03:07 -0500 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-12-10 20:03:07 -0500 |
commit | c17b200f6d0cb136851b798f280aba9b3862c337 (patch) | |
tree | ff517440354dfafe650a9f6542a32e7e2d161eb3 | |
parent | 853fbfb7a76cc81c2b4f47e094be159263c88a7a (diff) | |
parent | ca70b29bbb1818764b98196f8c28a1255a17965c (diff) |
Merge branches 'master' and 'master' of https://github.com/browngraphicslab/Dash-Web
-rw-r--r-- | src/client/util/ParagraphNodeSpec.ts | 6 | ||||
-rw-r--r-- | src/client/util/RichTextRules.ts | 14 | ||||
-rw-r--r-- | src/client/util/RichTextSchema.tsx | 2 | ||||
-rw-r--r-- | src/client/util/TooltipTextMenu.tsx | 6 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 2 |
5 files changed, 26 insertions, 4 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; diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx index f41846038..fac8f4027 100644 --- a/src/client/util/RichTextSchema.tsx +++ b/src/client/util/RichTextSchema.tsx @@ -302,7 +302,7 @@ export const marks: { [index: string]: MarkSpec } = { attrs: { color: { default: "#000" } }, - inclusive: false, + inclusive: true, parseDOM: [{ tag: "span", getAttrs(dom: any) { return { color: dom.getAttribute("color") }; diff --git a/src/client/util/TooltipTextMenu.tsx b/src/client/util/TooltipTextMenu.tsx index 01d566831..f29dbf2e4 100644 --- a/src/client/util/TooltipTextMenu.tsx +++ b/src/client/util/TooltipTextMenu.tsx @@ -839,9 +839,11 @@ export class TooltipTextMenu { } public static insertColor(color: String, state: EditorState<any>, dispatch: any) { - if (state.selection.empty) return false; - const colorMark = state.schema.mark(state.schema.marks.pFontColor, { color: color }); + if (state.selection.empty) { + dispatch(state.tr.addStoredMark(colorMark)); + return false; + } dispatch(state.tr.addMark(state.selection.from, state.selection.to, colorMark)); } diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 9219da80b..727d631c4 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -140,7 +140,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu } onKeyDown = (e: React.KeyboardEvent) => { - if (e.altKey && e.key === "t" && !(e.nativeEvent as any).StopPropagationForReal) { + if (e.altKey && (e.key === "†" || e.key === "t") && !(e.nativeEvent as any).StopPropagationForReal) { (e.nativeEvent as any).StopPropagationForReal = true; // e.stopPropagation() doesn't seem to work... e.stopPropagation(); if (!StrCast(this.Document.showTitle)) this.Document.showTitle = "title"; |