diff options
author | bobzel <zzzman@gmail.com> | 2025-04-10 14:44:07 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2025-04-10 14:44:07 -0400 |
commit | 75e76f1ec098ea9cbcd76432002da1bb73d74eba (patch) | |
tree | 0a152c9d48877715f037c045ca3c70265849a08c /src/client/views | |
parent | aff4fff58655ff48613b2519b55787955a766667 (diff) |
fixed removing predictive prompt. fixed first letter typed after predictive prompt
Diffstat (limited to 'src/client/views')
-rw-r--r-- | src/client/views/nodes/formattedText/DailyJournal.tsx | 23 | ||||
-rw-r--r-- | src/client/views/nodes/formattedText/FormattedTextBox.tsx | 19 |
2 files changed, 26 insertions, 16 deletions
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<FieldViewProps>() { @observable journalDate: string; @@ -109,7 +109,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() 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<FieldViewProps>() 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<FieldViewProps>() 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<FieldViewProps>() 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<FieldViewProps>() // 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<FieldViewProps>() } @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<FormattedTextB public static LayoutString(fieldStr: string) { return FieldView.LayoutString(FormattedTextBox, fieldStr); } - public static MakeConfig(rules?: RichTextRules, textBox?: FormattedTextBox) { + public static MakeConfig(rules?: RichTextRules, textBox?: FormattedTextBox, plugs?: Plugin[]) { return { schema, plugins: [ @@ -89,6 +89,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB keymap(baseKeymap), new Plugin({ props: { attributes: { class: 'ProseMirror-example-setup-style' } } }), new Plugin({ view: () => new FormattedTextBoxComment() }), + ...(plugs ?? []), ], }; } @@ -140,6 +141,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB public ApplyingChange: string = ''; @observable _showSidebar = false; + @observable _userPlugins: Plugin[] = []; @computed get fontColor() { return this._props.styleProvider?.(this.dataDoc, this._props, StyleProp.FontColor) as string; } // prettier-ignore @computed get fontSize() { return this._props.styleProvider?.(this.dataDoc, this._props, StyleProp.FontSize) as string; } // prettier-ignore @@ -153,7 +155,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB } // eslint-disable-next-line no-return-assign - @computed get config() { return FormattedTextBox.MakeConfig(this._rules = new RichTextRules(this.Document, this), this); } // prettier-ignore + @computed get config() { return FormattedTextBox.MakeConfig(this._rules = new RichTextRules(this.Document, this), this, this._userPlugins ?? []); } // prettier-ignore @computed get recordingDictation() { return this.dataDoc?.mediaState === mediaState.Recording; } // prettier-ignore @computed get SidebarShown() { return !!(this._showSidebar || this.layoutDoc._layout_showSidebar); } // prettier-ignore @computed get allSidebarDocs() { return DocListCast(this.dataDoc[this.sidebarKey]); } // prettier-ignore @@ -1224,6 +1226,17 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB if (nh) this.layoutDoc._nativeHeight = scrollHeight; }; + addPlugin = (plugin: Plugin) => { + 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<FormattedTextB } else if (!separated && node.isBlock) { text += '\n'; separated = true; - } else if (node.type.name === 'hard_break') { + } else if (node.type.name === schema.nodes.hard_break.name) { text += '\n'; } }, |