aboutsummaryrefslogtreecommitdiff
path: root/src/fields/RichTextField.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-04-21 13:48:58 -0400
committerbobzel <zzzman@gmail.com>2025-04-21 13:48:58 -0400
commit17e24e780b54f2f7015c0ca955c3aa5091bba19c (patch)
treeb13002c92d58cb52a02b46e4e1d578f1d57125f2 /src/fields/RichTextField.ts
parent22a40443193320487c27ce02bd3f134d13cb7d65 (diff)
parent1f294ef4a171eec72a069a9503629eaf7975d983 (diff)
merged with master and cleaned up outpainting a bit.
Diffstat (limited to 'src/fields/RichTextField.ts')
-rw-r--r--src/fields/RichTextField.ts29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts
index bcef1fefc..68a3737bf 100644
--- a/src/fields/RichTextField.ts
+++ b/src/fields/RichTextField.ts
@@ -42,7 +42,8 @@ export class RichTextField extends ObjectField {
return this.Text;
}
- // AARAV ADD=
+ // AARAV ADD
+
static ToProsemirrorDoc = (content: Record<string, unknown>[], selection: Record<string, unknown>) => ({
doc: {
type: 'doc',
@@ -86,7 +87,33 @@ export class RichTextField extends ObjectField {
{ type: 'text', anchor: 2 + plaintext.length - (selectBack ?? 0), head: 2 + plaintext.length }
);
+ // 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) =>
+ RichTextField.ToProsemirrorDoc(
+ textSegments.map(seg => ({
+ type: 'paragraph', // Each segment becomes its own paragraph
+ content: [...RichTextField.ToProsemirrorTextContent(seg.text, seg.styles), ...(imgDocId ? RichTextField.ToProsemirrorDashDocContent(imgDocId) : [])],
+ })),
+ (textLen => ({
+ type: 'text',
+ 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 ||
+
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(''));
+ }
+
+ // AARAV ADD
}