diff options
author | bobzel <zzzman@gmail.com> | 2025-03-07 14:21:29 -0500 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2025-03-07 14:21:29 -0500 |
commit | 54bfa54b498f7a7c5813c2f5d0ff3005d6ff44ab (patch) | |
tree | 86de14a32b074548d8215cff45ff31b402969a40 /src | |
parent | 010d7e9bbea5616d058c88de284905eecc145834 (diff) |
fixed selection of default journal text
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/formattedText/DailyJournal.tsx | 2 | ||||
-rw-r--r-- | src/fields/RichTextField.ts | 50 |
2 files changed, 14 insertions, 38 deletions
diff --git a/src/client/views/nodes/formattedText/DailyJournal.tsx b/src/client/views/nodes/formattedText/DailyJournal.tsx index c8f049ecf..dfd19ae97 100644 --- a/src/client/views/nodes/formattedText/DailyJournal.tsx +++ b/src/client/views/nodes/formattedText/DailyJournal.tsx @@ -62,7 +62,7 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>() { text: placeholderText, styles: { fontSize: 14, color: 'gray' } }, ], undefined, - placeholderText.length - 2 + placeholderText.length ); console.log('Current text field:', this.dataDoc[this.fieldKey]); diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts index 8f4d782b4..81b6c9ea9 100644 --- a/src/fields/RichTextField.ts +++ b/src/fields/RichTextField.ts @@ -87,57 +87,33 @@ export class RichTextField extends ObjectField { { type: 'text', anchor: 2 + plaintext.length - (selectBack ?? 0), head: 2 + plaintext.length } ); - - // AARAV ADD + // AARAV ADD // takes in text segments instead of single text field - private static ToProsemirrorSegmented = ( - textSegments: { text: string; styles?: { bold?: boolean; italic?: boolean; fontSize?: number; color?: string } }[], - imgDocId?: string, - selectBack?: number - ) => + private static ToProsemirrorSegmented = (textSegments: { text: string; styles?: { bold?: boolean; italic?: boolean; fontSize?: number; color?: string } }[], imgDocId?: string, selectBack?: number) => RichTextField.ToProsemirrorDoc( textSegments.map(seg => ({ type: 'paragraph', // Each segment becomes its own paragraph - content: [ - ...RichTextField.ToProsemirrorTextContent(seg.text, seg.styles), - ...(imgDocId ? RichTextField.ToProsemirrorDashDocContent(imgDocId) : []), - ], + content: [...RichTextField.ToProsemirrorTextContent(seg.text, seg.styles), ...(imgDocId ? RichTextField.ToProsemirrorDashDocContent(imgDocId) : [])], })), - { + (textLen => ({ type: 'text', - anchor: 2 + textSegments.map(seg => seg.text).join('').length - (selectBack ?? 0), - head: 2 + textSegments.map(seg => seg.text).join('').length, - } + anchor: textLen - (selectBack ?? 0), + head: textLen, + }))(2 * textSegments.length + textSegments.map(seg => seg.text).join('').length - 1) + // selection/doc end = text length + 2 for each paragraph. subtract 1 to set selection inside of end of last paragraph ); - - // AARAV ADD || - + // AARAV ADD || - public static textToRtf( - text: string, - imgDocId?: string, - styles?: { bold?: boolean; italic?: boolean; fontSize?: number; color?: string }, - selectBack?: number - ) { - return new RichTextField( - JSON.stringify(RichTextField.ToProsemirror(text, imgDocId, styles, selectBack)), text); + public static textToRtf(text: string, imgDocId?: string, styles?: { bold?: boolean; italic?: boolean; fontSize?: number; color?: string }, selectBack?: number) { + return new RichTextField(JSON.stringify(RichTextField.ToProsemirror(text, imgDocId, styles, selectBack)), text); } // AARAV ADD - public static textToRtfFormat( - textSegments: { text: string; styles?: { bold?: boolean; italic?: boolean; fontSize?: number; color?: string } }[], - imgDocId?: string, - selectBack?: number - ) { - return new RichTextField( - JSON.stringify(RichTextField.ToProsemirrorSegmented(textSegments, imgDocId, selectBack)), - textSegments.map(seg => seg.text).join('')); + public static textToRtfFormat(textSegments: { text: string; styles?: { bold?: boolean; italic?: boolean; fontSize?: number; color?: string } }[], imgDocId?: string, selectBack?: number) { + return new RichTextField(JSON.stringify(RichTextField.ToProsemirrorSegmented(textSegments, imgDocId, selectBack)), textSegments.map(seg => seg.text).join('')); } // AARAV ADD - - - } |