aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-02-22 13:05:44 -0500
committerBob Zeleznik <zzzman@gmail.com>2020-02-22 13:05:44 -0500
commitdfa1f71ad8c2d69274c67fe16c0dd6ceb53ec75a (patch)
treec5b3cbd8bd6b8c67f5077e91d8be198322ac4e5d
parentf4cb0d558191d4d1ca5b71ac9020d71bfa6de1f1 (diff)
fixed textboxes with templates so that edited text is written to the doc but the doc updates when templates change and the text hasn't been edited.
-rw-r--r--src/client/views/nodes/FormattedTextBox.tsx19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/client/views/nodes/FormattedTextBox.tsx b/src/client/views/nodes/FormattedTextBox.tsx
index 9700911b8..3b64e4cf3 100644
--- a/src/client/views/nodes/FormattedTextBox.tsx
+++ b/src/client/views/nodes/FormattedTextBox.tsx
@@ -189,13 +189,13 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps &
const curTemp = Cast(this.props.Document._textTemplate, RichTextField);
if (!this._applyingChange) {
this._applyingChange = true;
- if (!curTemp || curText) {
- if (Doc.GetProto(this.props.Document) === this.dataDoc) {
- this.dataDoc[this.props.fieldKey + "-lastModified"] = new DateField(new Date(Date.now()));
- this.dataDoc[this.props.fieldKey] = new RichTextField(JSON.stringify(state.toJSON()), curText);
- }
- } else {
+ this.dataDoc[this.props.fieldKey + "-lastModified"] = new DateField(new Date(Date.now()));
+ if (!curTemp || curText) { // if no template, or there's text, write it to the document. (if this is driven by a template, then this overwrites the template text which is intended)
+ this.dataDoc[this.props.fieldKey] = new RichTextField(JSON.stringify(state.toJSON()), curText);
+ this.dataDoc[this.props.fieldKey +"-noTemplate"] = curTemp?.Text !== curText;
+ } else { // if we've deleted all the text in a note driven by a template, then restore the template data
this._editorView.updateState(EditorState.fromJSON(this.config, JSON.parse(curTemp.Data)));
+ this.dataDoc[this.props.fieldKey +"-noTemplate"] = undefined;
}
this._applyingChange = false;
}
@@ -504,12 +504,11 @@ export class FormattedTextBox extends DocAnnotatableComponent<(FieldViewProps &
this._reactionDisposer = reaction(
() => {
- const curText = Cast(this.dataDoc[this.props.fieldKey], RichTextField, null);
- const field = !curText.Text && this.props.Document._textTemplate ? Cast(this.props.Document._textTemplate, RichTextField, null) : curText;
- return field?.Data || RichTextUtils.Initialize();
+ if (this.dataDoc[this.props.fieldKey +"-noTemplate"] || !this.props.Document._textTemplate) return undefined;
+ return Cast(this.props.Document._textTemplate, RichTextField, null).Data;
},
incomingValue => {
- if (this._editorView && !this._applyingChange) {
+ if (incomingValue !== undefined && this._editorView && !this._applyingChange) {
const updatedState = JSON.parse(incomingValue);
this._editorView.updateState(EditorState.fromJSON(this.config, updatedState));
this.tryUpdateHeight();