aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/ProsemirrorExampleTransfer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/ProsemirrorExampleTransfer.ts')
-rw-r--r--src/client/util/ProsemirrorExampleTransfer.ts30
1 files changed, 10 insertions, 20 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);