aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-08-26 17:42:19 -0400
committerbob <bcz@cs.brown.edu>2019-08-26 17:42:19 -0400
commit237b5f67733b25686b825573298818f3ea443876 (patch)
treea037fb83a484654ad7d4ff2cad8e8acbedefe111
parent094bbd52f2b55f501357a9f6b057042ad7684f27 (diff)
try another branch
-rw-r--r--src/client/util/ProsemirrorExampleTransfer.ts8
-rw-r--r--src/client/util/RichTextSchema.tsx24
2 files changed, 21 insertions, 11 deletions
diff --git a/src/client/util/ProsemirrorExampleTransfer.ts b/src/client/util/ProsemirrorExampleTransfer.ts
index 3cdfba59a..78b992ac8 100644
--- a/src/client/util/ProsemirrorExampleTransfer.ts
+++ b/src/client/util/ProsemirrorExampleTransfer.ts
@@ -93,13 +93,13 @@ export default function buildKeymap<S extends Schema<any>>(schema: S, mapKeys?:
var marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks());
let depth = range && range.depth ? range.depth : 0;
let nodeType = depth == 2 ? schema.nodes.cap_alphabet_list : depth == 4 ? schema.nodes.roman_list : depth == 6 ? schema.nodes.alphabet_list : schema.nodes.ordered_list;
- let nodeTypeMark = depth == 2 ? schema.marks.mcap_alphabet_list : depth == 4 ? schema.marks.mroman_list : depth == 6 ? schema.marks.malphabet_list : schema.marks.mordered_list;
+ let nodeTypeMark = schema.marks.mbulletType.create({ bulletType: depth == 2 ? "upper-alpha" : depth == 4 ? "lower-roman" : depth == 6 ? "lower-alpha" : "decimal" });
let created = levelMark(depth);
- if (!sinkListItem(nodeType /*schema.nodes.list_item */)(state, (tx2: Transaction) => {
+ if (!sinkListItem(schema.nodes.list_item)(state, (tx2: Transaction) => {
const resolvedPos = tx2.doc.resolve(range!.start);
let ns = new NodeSelection(resolvedPos);
- let tx3 = tx2.addMark(ns.from - 1, ns.to, created).addMark(ns.from - 1, ns.to, nodeTypeMark as any).setSelection(TextSelection.create(tx2.doc, ns.to - (depth == 0 ? 3 : 1)));
+ let tx3 = tx2.removeMark(ns.from - 1, ns.to, created).removeMark(ns.from - 1, ns.to, nodeTypeMark as any).addMark(ns.from - 1, ns.to, created).addMark(ns.from - 1, ns.to, nodeTypeMark as any).setSelection(TextSelection.create(tx2.doc, ns.to - (depth == 0 ? 3 : 1)));
marks && tx3.ensureMarks([...marks, created]);
marks && tx3.setStoredMarks([...marks, created]);
@@ -110,7 +110,7 @@ export default function buildKeymap<S extends Schema<any>>(schema: S, mapKeys?:
if (!wrapInList(nodeType)(newstate.state, (tx2: Transaction) => {
const resolvedPos = tx2.doc.resolve(range!.start);
let ns = new TextSelection(resolvedPos, tx2.doc.resolve(range!.end + 1)); // new NodeSelection(resolvedPos);
- let tx3 = tx2.setSelection(ns).removeMark(ns.from, ns.to, created).addMark(ns.from, ns.to, created).setSelection(TextSelection.create(tx2.doc, ns.to));
+ let tx3 = tx2.setSelection(ns).removeMark(ns.from, ns.to, created).removeMark(ns.from, ns.to, nodeTypeMark as any).addMark(ns.from - 1, ns.to, nodeTypeMark as any).addMark(ns.from, ns.to, created).setSelection(TextSelection.create(tx2.doc, ns.to));
let tx4 = depth > 0 ? tx3.insertText(" ").setSelection(TextSelection.create(tx2.doc, ns.to - 2, ns.to + 2)).deleteSelection() : tx3;
marks && tx4.ensureMarks([...marks, created]);
marks && tx4.setStoredMarks([...marks, created]);
diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx
index f128162c2..6e3d9ab77 100644
--- a/src/client/util/RichTextSchema.tsx
+++ b/src/client/util/RichTextSchema.tsx
@@ -178,6 +178,14 @@ export const nodes: { [index: string]: NodeSpec } = {
bulletStyle: { default: "decimal" },
},
toDOM(node: Node<any>) {
+ let first = node.firstChild;
+ while (first) {
+ if (first.marks.find((m) => m.type === schema.marks.mbulletType)) {
+ let x = first.marks.find((m) => m.type === schema.marks.mbulletType);
+ return ['ol', { style: `list-style: ${(x as any).attrs.bulletType}` }, 0]
+ }
+ first = first.firstChild;
+ }
return ['ol', { style: `list-style: ${node.attrs.bulletStyle}` }, 0]
}
},
@@ -319,13 +327,15 @@ export const marks: { [index: string]: MarkSpec } = {
toDOM: () => ['sup']
},
- malphabet_list: {
- },
- mcap_alphabet_list: {
- },
- mroman_list: {
- },
- mo_list: {
+ mbulletType: {
+ attrs: {
+ bulletType: { default: "decimal" }
+ },
+ toDOM(node: any) {
+ return ['span', {
+ style: `background: ${node.attrs.bulletType == "decimal" ? "yellow" : node.attrs.bulletType === "upper-alpha" ? "blue" : "green"}`
+ }];
+ }
},
highlight: {