diff options
author | bobzel <zzzman@gmail.com> | 2024-05-14 13:29:41 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-05-14 13:29:41 -0400 |
commit | 49d9406aaba666d88068be970b63345cb2535f9f (patch) | |
tree | 5c5d8a5341aacaf4bd8dc3ef41dcb481b0de52b7 /src/client/views/nodes/formattedText/FormattedTextBox.tsx | |
parent | 297f84678f8efb79ed2dc56693520b1e5a00da2e (diff) | |
parent | 2caf7b7bb80b663b6ba585f88cdbd2d725f8505e (diff) |
merged with master
Diffstat (limited to 'src/client/views/nodes/formattedText/FormattedTextBox.tsx')
-rw-r--r-- | src/client/views/nodes/formattedText/FormattedTextBox.tsx | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index bae93beec..43010b2ed 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -981,13 +981,10 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB }; animateRes = (resIndex: number, newText: string) => { - if (!this._editorView) return; if (resIndex < newText.length) { - const marks = this._editorView.state.storedMarks ?? []; - this._editorView.dispatch(this._editorView.state.tr.insertText(newText[resIndex]).setStoredMarks(marks)); - setTimeout(() => { - this.animateRes(resIndex + 1, newText); - }, 20); + const marks = this._editorView?.state.storedMarks ?? []; + this._editorView?.dispatch(this._editorView?.state.tr.insertText(newText[resIndex]).setStoredMarks(marks)); + setTimeout(() => this.animateRes(resIndex + 1, newText), 20); } }; @@ -996,15 +993,11 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB let res = await gptAPICall((this.dataDoc.text as RichTextField)?.Text, GPTCallType.COMPLETION); if (!res) { this.animateRes(0, 'Something went wrong.'); - } else { - if (!this._editorView) return; - // No animation - // this._editorView.dispatch(this._editorView.state.tr.insertText(res)); - - // Animation - // Set selection at end - const sel = Selection.atEnd(this._editorView.state.doc); - this._editorView.dispatch(this._editorView.state.tr.setSelection(sel)); + } else if (this._editorView) { + const { dispatch, state } = this._editorView; + // for no animation, use: dispatch(state.tr.insertText(res)); + // for animted response starting at end of text, use: + dispatch(state.tr.setSelection(Selection.atEnd(state.doc))); this.animateRes(0, '\n\n' + res); } } catch (err) { |