aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2019-08-27 00:38:19 -0400
committerBob Zeleznik <zzzman@gmail.com>2019-08-27 00:38:19 -0400
commit249038c576845027e91fe9e20cc791602c22d25d (patch)
tree794ea31f4ba7e7f143b7bc67eec02511984c830b
parent58300460307b2c944f1dd2d0d3b8e2515f529f72 (diff)
working except for moving multiple nodes at different levels at the same time
-rw-r--r--src/client/util/ProsemirrorExampleTransfer.ts30
-rw-r--r--src/client/util/RichTextSchema.tsx5
2 files changed, 13 insertions, 22 deletions
diff --git a/src/client/util/ProsemirrorExampleTransfer.ts b/src/client/util/ProsemirrorExampleTransfer.ts
index 238d37800..052fb0c6d 100644
--- a/src/client/util/ProsemirrorExampleTransfer.ts
+++ b/src/client/util/ProsemirrorExampleTransfer.ts
@@ -79,14 +79,6 @@ export default function buildKeymap<S extends Schema<any>>(schema: S, mapKeys?:
bind("Mod-s", TooltipTextMenu.insertStar);
-
- let levelMark = (depth: number) => {
- let p10 = schema.marks.pFontSize.create({ fontSize: 10 });
- let p14 = schema.marks.pFontSize.create({ fontSize: 14 });
- let p18 = schema.marks.pFontSize.create({ fontSize: 18 });
- let p24 = schema.marks.pFontSize.create({ fontSize: 24 });
- return depth == 0 ? p24 : depth == 2 ? p18 : depth == 4 ? p14 : p10;
- }
let bulletFunc = (state: EditorState<S>, dispatch: (tx: Transaction<S>) => void) => {
var ref = state.selection;
var range = ref.$from.blockRange(ref.$to);
@@ -94,7 +86,6 @@ export default function buildKeymap<S extends Schema<any>>(schema: S, mapKeys?:
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 = schema.marks.mbulletType.create({ bulletType: depth == 2 ? "upper-alpha" : depth == 4 ? "lower-roman" : depth == 6 ? "lower-alpha" : "decimal" });
- let created = levelMark(depth);
if (!sinkListItem(schema.nodes.list_item)(state, (tx2: Transaction) => {
const resolvedPos = tx2.doc.resolve(range!.start);
@@ -106,9 +97,9 @@ export default function buildKeymap<S extends Schema<any>>(schema: S, mapKeys?:
}
}
let ns = new NodeSelection(resolvedPos);
- let tx3 = tx2.removeMark(ns.from - 1, ns.to, created).addMark(ns.from - 1, ns.to, created).setSelection(TextSelection.create(tx2.doc, ns.to - (depth == 0 ? 3 : 1)));
- marks && tx3.ensureMarks([...marks.filter(m => m.type !== schema.marks.pFontSize), created]);
- marks && tx3.setStoredMarks([...marks.filter(m => m.type !== schema.marks.pFontSize), created]);
+ let tx3 = tx2.setSelection(TextSelection.create(tx2.doc, ns.to - (depth == 0 ? 3 : 1)));
+ marks && tx3.ensureMarks([...marks]);
+ marks && tx3.setStoredMarks([...marks]);
dispatch(tx3);
})) {
let sxf = state.tr.setSelection(TextSelection.create(state.doc, range!.start, range!.end));
@@ -116,10 +107,10 @@ 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 tx4 = depth > 0 ? tx3.insertText(" ").setSelection(TextSelection.create(tx2.doc, ns.to - 2, ns.to + 2)).deleteSelection() : tx3;
- marks && tx4.ensureMarks([...marks.filter(m => m.type !== schema.marks.pFontSize), created]);
- marks && tx4.setStoredMarks([...marks.filter(m => m.type !== schema.marks.pFontSize), created]);
+ let tx3 = tx2.setSelection(ns).setSelection(TextSelection.create(tx2.doc, ns.to));
+ let tx4 = tx3;
+ marks && tx4.ensureMarks([...marks]);
+ marks && tx4.setStoredMarks([...marks]);
dispatch(tx4);
})) {
@@ -135,7 +126,6 @@ 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 > 3 ? range.depth - 4 : 0;
let nodeTypeMark = schema.marks.mbulletType.create({ bulletType: depth == 2 ? "upper-alpha" : depth == 4 ? "lower-roman" : depth == 6 ? "lower-alpha" : "decimal" });
- let created = levelMark(range && range.depth ? range.depth - 4 : 0);
liftListItem(schema.nodes.list_item)(state, (tx2: Transaction) => {
try {
const resolvedPos = tx2.doc.resolve(Math.round((range!.start + range!.end) / 2));
@@ -152,10 +142,10 @@ export default function buildKeymap<S extends Schema<any>>(schema: S, mapKeys?:
let ns = new NodeSelection(tx2.doc.resolve(nodeIndex));
if (resolvedPos.nodeAfter && resolvedPos.nodeAfter.type.name === "list_item")
ns = new NodeSelection(tx2.doc.resolve(nodeIndex + 1));
- let tx3 = tx2.setSelection(ns).removeMark(ns.from - 1, ns.to, created).addMark(ns.from - 1, ns.to, created).setSelection(TextSelection.create(tx2.doc, ns.to));
+ let tx3 = tx2.setSelection(ns).setSelection(TextSelection.create(tx2.doc, ns.to));
- marks && tx3.ensureMarks([...marks.filter(m => m.type !== schema.marks.pFontSize), created]);
- marks && tx3.setStoredMarks([...marks.filter(m => m.type !== schema.marks.pFontSize), created]);
+ marks && tx3.ensureMarks([...marks]);
+ marks && tx3.setStoredMarks([...marks]);
dispatch(tx3);
} catch (e) {
dispatch(tx2);
diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx
index 37813958a..26960e889 100644
--- a/src/client/util/RichTextSchema.tsx
+++ b/src/client/util/RichTextSchema.tsx
@@ -178,7 +178,8 @@ export const nodes: { [index: string]: NodeSpec } = {
bulletStyle: { default: "decimal" },
},
toDOM(node: Node<any>) {
- return ['ol', { style: `list-style: ${node.attrs.bulletStyle}` }, 0]
+ let fsize = node.attrs.bulletStyle === "decimal" ? 24 : node.attrs.bulletStyle === "upper-alpha" ? 18 : node.attrs.bulletStyle === "lower-roman" ? 14 : 10;
+ return ['ol', { style: `list-style: ${node.attrs.bulletStyle}; font-size: ${fsize}` }, 0]
}
},
alphabet_list: {
@@ -278,7 +279,7 @@ export const marks: { [index: string]: MarkSpec } = {
// :: MarkSpec An emphasis mark. Rendered as an `<em>` element.
// Has parse rules that also match `<i>` and `font-style: italic`.
em: {
- parseDOM: [{ tag: "i" }, { tag: "em" }, { style: "font-style=italic" }],
+ parseDOM: [{ tag: "i" }, { tag: "em" }, { style: "font-style: italic" }],
toDOM() { return emDOM; }
},