From 4bbfe0fad535033309e352311fae64520b9068a6 Mon Sep 17 00:00:00 2001
From: Lauren <victor_kalev@brown.edu>
Date: Thu, 28 Oct 2021 16:07:11 -0400
Subject: adding eraser tool to menu

---
 src/client/views/nodes/button/FontIconBox.tsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/client/views/nodes/button/FontIconBox.tsx')

diff --git a/src/client/views/nodes/button/FontIconBox.tsx b/src/client/views/nodes/button/FontIconBox.tsx
index 33fa23805..14b1cbb5d 100644
--- a/src/client/views/nodes/button/FontIconBox.tsx
+++ b/src/client/views/nodes/button/FontIconBox.tsx
@@ -766,7 +766,7 @@ Scripting.addGlobal(function setActiveInkTool(tool: string, checkResult?: boolea
             Doc.UserDoc().activeInkTool = InkTool.Pen;
             GestureOverlay.Instance.InkShape = tool;
         }
-    } else if (tool) { // pen
+    } else if (tool) { // pen or eraser
         if (Doc.UserDoc().activeInkTool === tool && !GestureOverlay.Instance.InkShape) {
             Doc.UserDoc().activeInkTool = InkTool.None;
         } else {
-- 
cgit v1.2.3-70-g09d2


From 4bad9d544879f5d59becb2c0e22c9ff5800f2890 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 3 Dec 2021 14:39:40 -0500
Subject: cleaned up text alignment buttons & initialization in formatted text
 box

---
 src/client/documents/Documents.ts                  |  1 +
 src/client/views/nodes/button/FontIconBox.tsx      | 26 ++-------------
 .../views/nodes/formattedText/FormattedTextBox.tsx |  6 ++--
 .../views/nodes/formattedText/RichTextMenu.tsx     | 39 +++++++++-------------
 4 files changed, 24 insertions(+), 48 deletions(-)

(limited to 'src/client/views/nodes/button/FontIconBox.tsx')

diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 5c5818f8f..80c3f9168 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -746,6 +746,7 @@ export namespace Docs {
             I.strokeEndMarker = arrowEnd;
             I.strokeDash = dash;
             I.tool = tool;
+            I["text-align"] = "center";
             I.title = "ink";
             I.x = options.x;
             I.y = options.y;
diff --git a/src/client/views/nodes/button/FontIconBox.tsx b/src/client/views/nodes/button/FontIconBox.tsx
index 14b1cbb5d..bd103dcf7 100644
--- a/src/client/views/nodes/button/FontIconBox.tsx
+++ b/src/client/views/nodes/button/FontIconBox.tsx
@@ -636,30 +636,10 @@ Scripting.addGlobal(function getActiveTextInfo(info: "family" | "size" | "color"
 Scripting.addGlobal(function setAlignment(align: "left" | "right" | "center", checkResult?: boolean) {
     const editorView = RichTextMenu.Instance?.TextView?.EditorView;
     if (checkResult) {
-        let active: string;
-        if (editorView) {
-            active = editorView?.state && RichTextMenu.Instance.getActiveAlignment();
-        } else {
-            active = StrCast(Doc.UserDoc().textAlign);
-        }
-        if (active === align) return Colors.MEDIUM_BLUE;
-        return "transparent";
+        return (editorView ? RichTextMenu.Instance.textAlign : Doc.UserDoc().textAlign) === align ? Colors.MEDIUM_BLUE : "transparent";
     }
-    SelectionManager.Docs().map(doc => doc.textAlign = align);
-    switch (align) {
-        case "left":
-            editorView?.state && RichTextMenu.Instance.alignLeft(editorView, editorView.dispatch);
-            break;
-        case "center":
-            editorView?.state && RichTextMenu.Instance.alignCenter(editorView, editorView.dispatch);
-            break;
-        case "right":
-            editorView?.state && RichTextMenu.Instance.alignRight(editorView, editorView.dispatch);
-            break;
-        default:
-            break;
-    }
-    Doc.UserDoc().textAlign = align;
+    if (editorView?.state) RichTextMenu.Instance.align(editorView, editorView.dispatch, align);
+    else Doc.UserDoc().textAlign = align;
 });
 
 Scripting.addGlobal(function setBulletList(mapStyle: "bullet" | "decimal", checkResult?: boolean) {
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
index e61f96852..4a6af86c1 100644
--- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx
+++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
@@ -1146,9 +1146,11 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
                 const startupText = Field.toString(this.dataDoc[fieldKey] as Field);
                 if (startupText) {
                     dispatch(state.tr.insertText(startupText));
-                } else if (!FormattedTextBox.LiveTextUndo) {
+                }
+                const textAlign = StrCast(this.dataDoc["text-align"], StrCast(Doc.UserDoc().textAlign, "left"));
+                if (textAlign !== "left") {
                     selectAll(this._editorView.state, (tr) => {
-                        this._editorView!.dispatch(tr.replaceSelectionWith(state.schema.nodes.paragraph.create({ align: "center" })));
+                        this._editorView!.dispatch(tr.replaceSelectionWith(state.schema.nodes.paragraph.create({ align: textAlign })));
                     });
                 }
             }
diff --git a/src/client/views/nodes/formattedText/RichTextMenu.tsx b/src/client/views/nodes/formattedText/RichTextMenu.tsx
index bd05af977..4814d6e9a 100644
--- a/src/client/views/nodes/formattedText/RichTextMenu.tsx
+++ b/src/client/views/nodes/formattedText/RichTextMenu.tsx
@@ -45,7 +45,7 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps>   {
     @observable private _activeFontSize: string = "13px";
     @observable private _activeFontFamily: string = "";
     @observable private activeListType: string = "";
-    @observable private activeAlignment: string = "left";
+    @observable private _activeAlignment: string = "left";
 
     @observable private brushMarks: Set<Mark> = new Set();
     @observable private showBrushDropdown: boolean = false;
@@ -86,6 +86,7 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps>   {
     @computed get fontColor() { return this._activeFontColor; }
     @computed get fontFamily() { return this._activeFontFamily; }
     @computed get fontSize() { return this._activeFontSize; }
+    @computed get textAlign() { return this._activeAlignment; }
 
     public delayHide = () => this._delayHide = true;
 
@@ -115,7 +116,7 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps>   {
         const activeHighlights = active.activeHighlights;
 
         this.activeListType = this.getActiveListStyle();
-        this.activeAlignment = this.getActiveAlignment();
+        this._activeAlignment = this.getActiveAlignment();
         this._activeFontFamily = !activeFamilies.length ? "Arial" : activeFamilies.length === 1 ? String(activeFamilies[0]) : "various";
         this._activeFontSize = !activeSizes.length ? "13px" : activeSizes[0];
         this._activeFontColor = !activeColors.length ? "black" : activeColors.length > 0 ? String(activeColors[0]) : "...";
@@ -388,29 +389,21 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps>   {
         dispatch?.(tr.replaceSelectionWith(newNode).removeMark(tr.selection.from - 1, tr.selection.from, mark));
         return true;
     }
-    alignCenter = (view: EditorView, dispatch: any) => {
-        return this.TextView.props.isSelected(true) && this.alignParagraphs(view, "center", dispatch);
-    }
-    alignLeft = (view: EditorView, dispatch: any) => {
-        return this.TextView.props.isSelected(true) && this.alignParagraphs(view, "left", dispatch);
-    }
-    alignRight = (view: EditorView, dispatch: any) => {
-        return this.TextView.props.isSelected(true) && this.alignParagraphs(view, "right", dispatch);
-    }
 
-    alignParagraphs(view: EditorView, align: "left" | "right" | "center", dispatch: any) {
-        var tr = view.state.tr;
-        view.state.doc.nodesBetween(view.state.selection.from, view.state.selection.to, (node, pos, parent, index) => {
-            if (node.type === schema.nodes.paragraph || node.type === schema.nodes.heading) {
-                tr = tr.setNodeMarkup(pos, node.type, { ...node.attrs, align }, node.marks);
-                return false;
-            }
+    align = (view: EditorView, dispatch: any, alignment: "left" | "right" | "center") => {
+        if (this.TextView.props.isSelected(true)) {
+            var tr = view.state.tr;
+            view.state.doc.nodesBetween(view.state.selection.from, view.state.selection.to, (node, pos, parent, index) => {
+                if ([schema.nodes.paragraph, schema.nodes.heading].includes(node.type)) {
+                    tr = tr.setNodeMarkup(pos, node.type, { ...node.attrs, align: alignment }, node.marks);
+                    return false;
+                }
+                view.focus();
+                return true;
+            });
             view.focus();
-            return true;
-        });
-        view.focus();
-        dispatch?.(tr);
-        return true;
+            dispatch?.(tr);
+        }
     }
 
     insetParagraph(state: EditorState<any>, dispatch: any) {
-- 
cgit v1.2.3-70-g09d2

