diff options
author | bobzel <zzzman@gmail.com> | 2025-06-10 19:06:31 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2025-06-10 19:06:31 -0400 |
commit | 403dcfb5e8b659f62ed51212ede3f5807caa58c6 (patch) | |
tree | 8d72f2d4c3a22c13c8f53f8e82355a887333f4ac /src/client/views/nodes/formattedText/FormattedTextBox.tsx | |
parent | 272534c8a7517d08c70928c96d487d84b14772f6 (diff) |
cleanup and streamlining of scrapbook code.
Diffstat (limited to 'src/client/views/nodes/formattedText/FormattedTextBox.tsx')
-rw-r--r-- | src/client/views/nodes/formattedText/FormattedTextBox.tsx | 44 |
1 files changed, 12 insertions, 32 deletions
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index 0c3179173..1768eb08d 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -8,7 +8,6 @@ import { baseKeymap, selectAll, splitBlock } from 'prosemirror-commands'; import { history } from 'prosemirror-history'; import { inputRules } from 'prosemirror-inputrules'; import { keymap } from 'prosemirror-keymap'; -import { runInAction } from 'mobx'; import { Fragment, Mark, Node, Slice } from 'prosemirror-model'; import { EditorState, NodeSelection, Plugin, Selection, TextSelection, Transaction } from 'prosemirror-state'; import { EditorView, NodeViewConstructor } from 'prosemirror-view'; @@ -65,7 +64,6 @@ import { removeMarkWithAttrs } from './prosemirrorPatches'; import { RichTextMenu, RichTextMenuPlugin } from './RichTextMenu'; import { RichTextRules } from './RichTextRules'; import { schema } from './schema_rts'; -import { tickStep } from 'd3'; // import * as applyDevTools from 'prosemirror-dev-tools'; export interface FormattedTextBoxProps extends FieldViewProps { @@ -310,30 +308,18 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB } }; - autoTag = async () => { + autoTag = () => { + const rawText = RTFCast(this.Document[this.fieldKey])?.Text ?? StrCast(this.Document[this.fieldKey]); + const callType = rawText.includes('[placeholder]') ? GPTCallType.CLASSIFYTEXTMINIMAL : GPTCallType.CLASSIFYTEXTFULL; - const layoutKey = Doc.LayoutDataKey(this.Document); - const rawText = RTFCast(this.Document[layoutKey])?.Text ?? StrCast(this.Document[layoutKey]); - - const callType = rawText.includes("[placeholder]") - ? GPTCallType.CLASSIFYTEXTMINIMAL - : GPTCallType.CLASSIFYTEXTFULL; - - gptAPICall(rawText, callType).then(desc => { - runInAction(() => { - // Clear existing tags - this.Document.$tags_chat = new List<string>(); - - // Split GPT response into tokens and push individually - const tokens = desc.trim().split(/\s+/); - tokens.forEach(tok => { - (this.Document.$tags_chat as List<string>).push(tok); - }); - - this.Document._layout_showTags = true; - }); - }); -}; + gptAPICall(rawText, callType).then( + action(desc => { + // Split GPT response into tokens and push individually & clear existing tags + this.Document.$tags_chat = new List<string>(desc.trim().split(/\s+/)); + this.Document._layout_showTags = true; + }) + ); + }; leafText = (node: Node) => { if (node.type === this.EditorView?.state.schema.nodes.dashField) { @@ -1298,13 +1284,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB { fireImmediately: true } ); - this._disposers.tagger = reaction( - () => ({ title: this.Document.title, sel: this._props.isSelected() }), - action(() => { - this.autoTag(); - }), - { fireImmediately: true } - ); + this._disposers.tagger = reaction(() => ({ title: this.Document.title, sel: this._props.isSelected() }), this.autoTag, { fireImmediately: true }); if (!this._props.dontRegisterView) { this._disposers.record = reaction( |