From 291d2fb28fa878eff190daf813854d9c0477ccb6 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 14 Aug 2020 17:29:55 -0400
Subject: cleaned up invocation of RichTextMenu

---
 .../views/nodes/formattedText/RichTextMenu.tsx     | 34 +++++++++-------------
 1 file changed, 14 insertions(+), 20 deletions(-)

(limited to 'src/client/views/nodes/formattedText/RichTextMenu.tsx')

diff --git a/src/client/views/nodes/formattedText/RichTextMenu.tsx b/src/client/views/nodes/formattedText/RichTextMenu.tsx
index b683fb25d..25b0279ba 100644
--- a/src/client/views/nodes/formattedText/RichTextMenu.tsx
+++ b/src/client/views/nodes/formattedText/RichTextMenu.tsx
@@ -16,7 +16,7 @@ import { unimplementedFunction, Utils } from "../../../../Utils";
 import { DocServer } from "../../../DocServer";
 import { LinkManager } from "../../../util/LinkManager";
 import { SelectionManager } from "../../../util/SelectionManager";
-import AntimodeMenu from "../../AntimodeMenu";
+import AntimodeMenu, { AntimodeMenuProps } from "../../AntimodeMenu";
 import { FieldViewProps } from "../FieldView";
 import { FormattedTextBox, FormattedTextBoxProps } from "./FormattedTextBox";
 import { updateBullets } from "./ProsemirrorExampleTransfer";
@@ -31,11 +31,11 @@ library.add(faBold, faItalic, faChevronLeft, faUnderline, faStrikethrough, faSup
 
 
 @observer
-export default class RichTextMenu extends AntimodeMenu {
+export default class RichTextMenu extends AntimodeMenu<AntimodeMenuProps>   {
     static Instance: RichTextMenu;
     public overMenu: boolean = false; // kind of hacky way to prevent selects not being selectable
 
-    private view?: EditorView;
+    public view?: EditorView;
     public editorProps: FieldViewProps & FormattedTextBoxProps | undefined;
 
     public _brushMap: Map<string, Set<Mark>> = new Map();
@@ -156,21 +156,7 @@ export default class RichTextMenu extends AntimodeMenu {
     public delayHide = () => this._delayHide = true;
 
     @action
-    changeView(view: EditorView) {
-        if ((view as any)?.TextView?.props.isSelected(true)) {
-            this.view = view;
-        }
-    }
-
-    update(view: EditorView, lastState: EditorState | undefined) {
-        RichTextMenu.Instance.updateFromDash(view, lastState, this.editorProps);
-    }
-
-    @action
-    public async updateFromDash(view: EditorView, lastState: EditorState | undefined, props: any) {
-        RichTextMenu.Instance.finalUpdateFromDash(view, lastState, props);
-    }
-    public async finalUpdateFromDash(view: EditorView, lastState: EditorState | undefined, props: any) {
+    public updateMenu(view: EditorView, lastState: EditorState | undefined, props: any) {
         if (!view || !(view as any).TextView?.props.isSelected(true)) {
             return;
         }
@@ -199,8 +185,7 @@ export default class RichTextMenu extends AntimodeMenu {
         this.activeHighlightColor = !activeHighlights.length ? "" : activeHighlights.length === 1 ? String(activeHighlights[0]) : "...";
 
         // update link in current selection
-        const targetTitle = await this.getTextLinkTargetTitle();
-        this.setCurrentLink(targetTitle);
+        this.getTextLinkTargetTitle().then(targetTitle => this.setCurrentLink(targetTitle));
     }
 
     setMark = (mark: Mark, state: EditorState<any>, dispatch: any, dontToggle: boolean = false) => {
@@ -1070,4 +1055,13 @@ export class ButtonDropdown extends React.Component<ButtonDropdownProps> {
             </div>
         );
     }
+}
+
+
+interface RichTextMenuPluginProps {
+    editorProps: any;
+}
+export class RichTextMenuPlugin extends React.Component<RichTextMenuPluginProps> {
+    render() { return null; }
+    update(view: EditorView, lastState: EditorState | undefined) { RichTextMenu.Instance?.updateMenu(view, lastState, this.props.editorProps); }
 }
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2


From 077a38dc22f6082974e639f8a020ceb179116958 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 14 Aug 2020 18:08:47 -0400
Subject: fixed some edge cses with richTextMenu synchronization.   added
 author field to delegates

---
 src/client/views/collections/CollectionMenu.tsx       | 4 +++-
 src/client/views/nodes/formattedText/RichTextMenu.tsx | 2 +-
 src/fields/Doc.ts                                     | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)

(limited to 'src/client/views/nodes/formattedText/RichTextMenu.tsx')

diff --git a/src/client/views/collections/CollectionMenu.tsx b/src/client/views/collections/CollectionMenu.tsx
index 0b3be8739..97d38d27e 100644
--- a/src/client/views/collections/CollectionMenu.tsx
+++ b/src/client/views/collections/CollectionMenu.tsx
@@ -429,7 +429,9 @@ export class CollectionFreeFormViewChrome extends React.Component<CollectionMenu
     @computed get selectedDoc() { return this.selectedDocumentView?.rootDoc; }
     @computed get isText() {
         if (this.selectedDoc) {
-            return this.selectedDoc[Doc.LayoutFieldKey(this.selectedDoc)] instanceof RichTextField;
+            const layoutField = Doc.LayoutField(this.selectedDoc);
+            return StrCast(layoutField).includes("FormattedText") ||
+                (layoutField instanceof Doc && StrCast(layoutField.layout).includes("FormattedText"));
         }
         else return false;
     }
diff --git a/src/client/views/nodes/formattedText/RichTextMenu.tsx b/src/client/views/nodes/formattedText/RichTextMenu.tsx
index 25b0279ba..e5cc62082 100644
--- a/src/client/views/nodes/formattedText/RichTextMenu.tsx
+++ b/src/client/views/nodes/formattedText/RichTextMenu.tsx
@@ -157,7 +157,7 @@ export default class RichTextMenu extends AntimodeMenu<AntimodeMenuProps>   {
 
     @action
     public updateMenu(view: EditorView, lastState: EditorState | undefined, props: any) {
-        if (!view || !(view as any).TextView?.props.isSelected(true)) {
+        if (!view || !(view as any).TextView?.props.isSelected(true) || !view.hasFocus()) {
             return;
         }
         this.view = view;
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index ea53bc9a2..b530b1cf7 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -781,6 +781,7 @@ export namespace Doc {
         if (doc) {
             const delegate = new Doc(id, true);
             delegate.proto = doc;
+            delegate.author = Doc.CurrentUserEmail;
             title && (delegate.title = title);
             return delegate;
         }
-- 
cgit v1.2.3-70-g09d2

