From 75e76f1ec098ea9cbcd76432002da1bb73d74eba Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 10 Apr 2025 14:44:07 -0400 Subject: fixed removing predictive prompt. fixed first letter typed after predictive prompt --- .../views/nodes/formattedText/DailyJournal.tsx | 23 ++++++++++------------ .../views/nodes/formattedText/FormattedTextBox.tsx | 19 +++++++++++++++--- 2 files changed, 26 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/formattedText/DailyJournal.tsx b/src/client/views/nodes/formattedText/DailyJournal.tsx index 26a86bc6e..797a9b812 100644 --- a/src/client/views/nodes/formattedText/DailyJournal.tsx +++ b/src/client/views/nodes/formattedText/DailyJournal.tsx @@ -1,14 +1,14 @@ -import { makeObservable, action, observable, autorun } from 'mobx'; +import { makeObservable, action, observable } from 'mobx'; import * as React from 'react'; import { Docs } from '../../../documents/Documents'; import { DocumentType } from '../../../documents/DocumentTypes'; import { ViewBoxAnnotatableComponent } from '../../DocComponent'; import { FieldView, FieldViewProps } from '../FieldView'; import { FormattedTextBox, FormattedTextBoxProps } from './FormattedTextBox'; -import { gptAPICall, GPTCallType, gptImageLabel } from '../../../apis/gpt/GPT'; +import { gptAPICall, GPTCallType } from '../../../apis/gpt/GPT'; import { RichTextField } from '../../../../fields/RichTextField'; -import { TextSelection } from 'prosemirror-state'; import { Plugin } from 'prosemirror-state'; +import { RTFCast } from '../../../../fields/Types'; export class DailyJournal extends ViewBoxAnnotatableComponent() { @observable journalDate: string; @@ -109,7 +109,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent() const { state, dispatch } = editorView; const { schema } = state; - const { from, to } = state.selection; + const { to } = state.selection; const insertPos = to; // cursor position const resolvedPos = state.doc.resolve(insertPos); @@ -121,7 +121,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent() let hasNewlineAfter = false; try { const nextNode = parentNode.child(indexInParent); - hasNewlineAfter = nextNode.type.name === 'hard_break' || nextNode.type.name === 'paragraph'; + hasNewlineAfter = nextNode.type.name === schema.nodes.hard_break.name || nextNode.type.name === schema.nodes.paragraph.name; } catch { hasNewlineAfter = false; } @@ -145,7 +145,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent() const predictedText = schema.text(text, [fontSizeMark, fontColorMark, fontItalicsMark]); // Insert styled text at cursor position - const transaction = state.tr.insert(insertPos, predictedText); + const transaction = state.tr.insert(insertPos, predictedText).setStoredMarks([state.schema.marks.pFontColor.create({ fontColor: 'gray' })]); // should probably instead inquire marks before predictive prompt dispatch(transaction); this.predictiveText = text; @@ -195,7 +195,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent() componentDidMount(): void { console.log('componentDidMount() triggered...'); - console.log('Text: ' + (this.Document.text as any)?.Text); + console.log('Text: ' + RTFCast(this.Document.text)?.Text); const editorView = this._ref.current?.EditorView; if (editorView) { @@ -203,13 +203,10 @@ export class DailyJournal extends ViewBoxAnnotatableComponent() // Add plugin to state if not already added const cleanupPlugin = this.createPredictiveCleanupPlugin(); - const newState = editorView.state.reconfigure({ - plugins: [...editorView.state.plugins, cleanupPlugin], - }); - editorView.updateState(newState); + this._ref.current?.addPlugin(cleanupPlugin); } - const rawText = (this.Document.text as any)?.Text ?? ''; + const rawText = RTFCast(this.Document.text)?.Text ?? ''; const isTextEmpty = !rawText || rawText === ''; const currentTitle = this.dataDoc.title || ''; @@ -234,7 +231,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent() } @action handleGeneratePrompts = async () => { - const rawText = (this.Document.text as any)?.Text ?? ''; + const rawText = RTFCast(this.Document.text)?.Text ?? ''; console.log('Extracted Journal Text:', rawText); console.log('Before Update:', this.Document.text, 'Type:', typeof this.Document.text); diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index a45b8a488..bef999e6d 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -78,7 +78,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent new FormattedTextBoxComment() }), + ...(plugs ?? []), ], }; } @@ -140,6 +141,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent { + const editorView = this.EditorView; + if (editorView) { + this._userPlugins.push(plugin); + const newState = editorView.state.reconfigure({ + plugins: [...editorView.state.plugins, plugin], + }); + editorView.updateState(newState); + } + }; + @computed get tagsHeight() { return this.DocumentView?.().showTags ? Math.max(0, 20 - Math.max(this._props.yPadding ?? 0, NumCast(this.layoutDoc._yMargin))) * this.ScreenToLocalBoxXf().Scale : 0; } @@ -1403,7 +1416,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent