aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/formattedText/DailyJournal.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-04-10 14:44:07 -0400
committerbobzel <zzzman@gmail.com>2025-04-10 14:44:07 -0400
commit75e76f1ec098ea9cbcd76432002da1bb73d74eba (patch)
tree0a152c9d48877715f037c045ca3c70265849a08c /src/client/views/nodes/formattedText/DailyJournal.tsx
parentaff4fff58655ff48613b2519b55787955a766667 (diff)
fixed removing predictive prompt. fixed first letter typed after predictive prompt
Diffstat (limited to 'src/client/views/nodes/formattedText/DailyJournal.tsx')
-rw-r--r--src/client/views/nodes/formattedText/DailyJournal.tsx23
1 files changed, 10 insertions, 13 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);