aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/views/nodes/FormattedTextBox.tsx9
-rw-r--r--src/server/database.ts40
2 files changed, 25 insertions, 24 deletions
diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx
index 8ea747b1c..a49497f8f 100644
--- a/src/client/views/nodes/FormattedTextBox.tsx
+++ b/src/client/views/nodes/FormattedTextBox.tsx
@@ -14,6 +14,8 @@ import { Main } from "../Main";
import { FieldView, FieldViewProps } from "./FieldView";
import "./FormattedTextBox.scss";
import React = require("react");
+import { TextField } from "../../../fields/TextField";
+import { KeyStore } from "../../../fields/KeyStore";
const { buildMenuItems } = require("prosemirror-example-setup");
const { menuBar } = require("prosemirror-menu");
@@ -55,15 +57,20 @@ export class FormattedTextBox extends React.Component<(FieldViewProps & Formatte
this.onChange = this.onChange.bind(this);
}
+ _applyingChange: boolean = false;
+
dispatchTransaction = (tx: Transaction) => {
if (this._editorView) {
const state = this._editorView.state.apply(tx);
this._editorView.updateState(state);
+ this._applyingChange = true;
this.props.Document.SetDataOnPrototype(
this.props.fieldKey,
JSON.stringify(state.toJSON()),
RichTextField
);
+ this.props.Document.SetDataOnPrototype(KeyStore.DocumentText, state.doc.textBetween(0, state.doc.content.size, "\n\n"), TextField);
+ this._applyingChange = false;
// doc.SetData(fieldKey, JSON.stringify(state.toJSON()), RichTextField);
}
}
@@ -105,7 +112,7 @@ export class FormattedTextBox extends React.Component<(FieldViewProps & Formatte
return field && field !== FieldWaiting ? field.Data : undefined;
},
field => {
- if (field && this._editorView) {
+ if (field && this._editorView && !this._applyingChange) {
this._editorView.updateState(
EditorState.fromJSON(config, JSON.parse(field))
);
diff --git a/src/server/database.ts b/src/server/database.ts
index c51d4a3f6..7914febf8 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -20,31 +20,25 @@ export class Database {
let newProm: Promise<void>;
const run = (): Promise<void> => {
return new Promise<void>(resolve => {
- collection.updateOne({ _id: id }, { $set: value }, {
- upsert: true
- }, (err, res) => {
- if (err) {
- console.log(err.message);
- console.log(err.errmsg);
- }
- // if (res) {
- // console.log(JSON.stringify(res.result));
- // }
- if (this.currentWrites[id] === newProm) {
- delete this.currentWrites[id];
- }
- resolve();
- callback();
- });
+ collection.updateOne({ _id: id }, { $set: value }, { upsert: true }
+ , (err, res) => {
+ if (err) {
+ console.log(err.message);
+ console.log(err.errmsg);
+ }
+ // if (res) {
+ // console.log(JSON.stringify(res.result));
+ // }
+ if (this.currentWrites[id] === newProm) {
+ delete this.currentWrites[id];
+ }
+ resolve();
+ callback();
+ });
});
};
- if (prom) {
- newProm = prom.then(run);
- this.currentWrites[id] = newProm;
- } else {
- newProm = run();
- this.currentWrites[id] = newProm;
- }
+ newProm = prom ? prom.then(run) : run();
+ this.currentWrites[id] = newProm;
}
}