From cfeaa00ebec604f69cf2559809ed19abe126411f Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 21 Jan 2021 00:25:53 -0500
Subject: fixed dropdown behavior of menu buttons -- specifically styleBrush

---
 .../views/nodes/formattedText/RichTextMenu.tsx     | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 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 9000018f4..992194e2b 100644
--- a/src/client/views/nodes/formattedText/RichTextMenu.tsx
+++ b/src/client/views/nodes/formattedText/RichTextMenu.tsx
@@ -56,7 +56,6 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps>   {
     @observable private activeListType: string = "";
     @observable private activeAlignment: string = "left";
 
-    @observable private brushIsEmpty: boolean = true;
     @observable private brushMarks: Set<Mark> = new Set();
     @observable private showBrushDropdown: boolean = false;
 
@@ -635,13 +634,12 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps>   {
             </div>;
 
         return (
-            <ButtonDropdown view={this.view} key={"brush dropdown"} button={button} dropdownContent={dropdownContent} openDropdownOnButton={true} />
+            <ButtonDropdown view={this.view} key={"brush dropdown"} button={button} openDropdownOnButton={false} dropdownContent={dropdownContent} />
         );
     }
 
     @action
     clearBrush() {
-        RichTextMenu.Instance.brushIsEmpty = true;
         RichTextMenu.Instance.brushMarks = new Set();
     }
 
@@ -649,26 +647,22 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps>   {
     fillBrush(state: EditorState<any>, dispatch: any) {
         if (!this.view) return;
 
-        if (this.brushIsEmpty) {
+        if (!Array.from(this.brushMarks.keys()).length) {
             const selected_marks = this.getMarksInSelection(this.view.state);
             if (selected_marks.size >= 0) {
                 this.brushMarks = selected_marks;
-                this.brushIsEmpty = !this.brushIsEmpty;
             }
         }
         else {
             const { from, to, $from } = this.view.state.selection;
             if (!this.view.state.selection.empty && $from && $from.nodeAfter) {
-                if (this.brushMarks && to - from > 0) {
+                if (to - from > 0) {
                     this.view.dispatch(this.view.state.tr.removeMark(from, to));
                     Array.from(this.brushMarks).filter(m => m.type !== schema.marks.user_mark).forEach((mark: Mark) => {
                         this.setMark(mark, this.view!.state, this.view!.dispatch);
                     });
                 }
             }
-            else {
-                this.brushIsEmpty = !this.brushIsEmpty;
-            }
         }
     }
 
@@ -816,8 +810,7 @@ export class RichTextMenu extends AntimodeMenu<AntimodeMenuProps>   {
                 <button className="remove-button" onPointerDown={e => this.deleteLink()}>Remove link</button>
             </div>;
 
-        return <ButtonDropdown view={this.view} key={"link button"} button={button} dropdownContent={dropdownContent}
-            openDropdownOnButton={true} link={true} />;
+        return <ButtonDropdown view={this.view} key={"link button"} button={button} dropdownContent={dropdownContent} openDropdownOnButton={true} link={true} />;
     }
 
     async getTextLinkTargetTitle() {
@@ -1026,6 +1019,7 @@ interface ButtonDropdownProps {
     openDropdownOnButton?: boolean;
     link?: boolean;
     pdf?: boolean;
+
 }
 
 @observer
@@ -1070,9 +1064,11 @@ export class ButtonDropdown extends React.Component<ButtonDropdownProps> {
         return (
             <div className="button-dropdown-wrapper" ref={node => this.ref = node}>
                 {!this.props.pdf ?
-                    <div className="antimodeMenu-button dropdown-button-combined" onPointerDown={this.onDropdownClick}>
+                    <div className="antimodeMenu-button dropdown-button-combined" onPointerDown={this.props.openDropdownOnButton ? this.onDropdownClick : undefined}>
                         {this.props.button}
-                        <div style={{ marginTop: "-8.5" }}><FontAwesomeIcon icon="caret-down" size="sm" /></div>
+                        <div style={{ marginTop: "-8.5", position: "relative" }} onPointerDown={!this.props.openDropdownOnButton ? this.onDropdownClick : undefined}>
+                            <FontAwesomeIcon icon="caret-down" size="sm" />
+                        </div>
                     </div>
                     :
                     <>
-- 
cgit v1.2.3-70-g09d2

