diff options
author | bob <bcz@cs.brown.edu> | 2019-06-12 12:35:59 -0400 |
---|---|---|
committer | bob <bcz@cs.brown.edu> | 2019-06-12 12:35:59 -0400 |
commit | a4f5005fedae93bd4bb1529561acaa8d4f0474c5 (patch) | |
tree | 6151c8f46a95b1738ebd518d64e821aedb0dc3b4 /src | |
parent | ce9adde20b611ea8300c402416ef41e4fb960919 (diff) |
"fixed" prosemirror serialization of 'star' schema node
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/RichTextSchema.tsx | 10 | ||||
-rw-r--r-- | src/client/util/TooltipTextMenu.tsx | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx index db62f3ac1..d1282403f 100644 --- a/src/client/util/RichTextSchema.tsx +++ b/src/client/util/RichTextSchema.tsx @@ -90,6 +90,7 @@ export const nodes: { [index: string]: NodeSpec } = { attrs: { visibility: { default: false }, oldtext: { default: undefined }, + oldtextslice: { default: undefined }, oldtextlen: { default: 0 } }, @@ -502,10 +503,9 @@ export const schema = new Schema({ nodes, marks }); const fromJson = schema.nodeFromJSON; schema.nodeFromJSON = (json: any) => { - if (json.type !== "star") { - return fromJson(json); + let node = fromJson(json); + if (json.type === "star") { + node.attrs.oldtext = Slice.fromJSON(schema, node.attrs.oldtextslice); } - let x = fromJson(json); - x.attrs.oldtext = Slice.fromJSON(x.attrs.oldtext); - return x; + return node; }
\ No newline at end of file diff --git a/src/client/util/TooltipTextMenu.tsx b/src/client/util/TooltipTextMenu.tsx index a2288a496..87a4c33a1 100644 --- a/src/client/util/TooltipTextMenu.tsx +++ b/src/client/util/TooltipTextMenu.tsx @@ -274,7 +274,7 @@ export class TooltipTextMenu { insertStar(state: EditorState<any>, dispatch: any) { console.log("creating star..."); - let newNode = schema.nodes.star.create({ visibility: false, oldtext: state.selection.content(), oldtextlen: state.selection.to - state.selection.from }); + let newNode = schema.nodes.star.create({ visibility: false, oldtext: state.selection.content(), oldtextslice: state.selection.content().toJSON(), oldtextlen: state.selection.to - state.selection.from }); if (dispatch) { console.log(newNode.attrs.oldtext.toString()); dispatch(state.tr.replaceSelectionWith(newNode)); |