Explorar el Código

tempory fix for wrong positions of custom context menu

which is caused by the bump of rum too.
Tienson Qin hace 3 años
padre
commit
3758a9e1c0

+ 7 - 4
src/main/frontend/components/content.cljs

@@ -153,10 +153,13 @@
 
     (rum/use-effect!
      (fn []
-       (let [^js el (rum/deref *el-ref)
-             {:keys [x y]} (util/calc-delta-rect-offset el js/document.documentElement)]
-         (set! (.. el -style -transform)
-               (str "translate3d(" (if (neg? x) x 0) "px," (if (neg? y) (- y 10) 0) "px" ",0)")))
+       (js/setTimeout
+        (fn []
+          (let [^js el (rum/deref *el-ref)
+               {:keys [x y]} (util/calc-delta-rect-offset el js/document.documentElement)]
+           (set! (.. el -style -transform)
+                 (str "translate3d(" (if (neg? x) x 0) "px," (if (neg? y) (- y 10) 0) "px" ",0)"))))
+        10)
        #())
      [])
 

+ 4 - 2
src/main/frontend/components/content.css

@@ -13,7 +13,9 @@
 
 #custom-context-menu {
   @apply rounded-md shadow-lg transition ease-out duration-100 transform
-  opacity-100 scale-100 absolute;
+  opacity-100 scale-100 absolute overflow-y-auto;
 
+  max-height: calc(100vh - 100px) !important;;
+  overflow-y: scroll;
   z-index: calc(var(--ls-z-index-level-1) + 1);
-}
+}

+ 9 - 4
src/main/frontend/handler/common.cljs

@@ -228,10 +228,15 @@
         client-y (gobj/get e "clientY")
         scroll-y (util/cur-doc-top)]
     (state/show-custom-context-menu! context-menu-content)
-    (when-let [context-menu (d/by-id "custom-context-menu")]
-      (d/set-style! context-menu
-                    :left (str client-x "px")
-                    :top (str (+ scroll-y client-y) "px")))))
+
+    ;; FIXME: use setTimeout here because rum renders lazily.
+    (js/setTimeout
+     (fn []
+       (when-let [context-menu (d/by-id "custom-context-menu")]
+        (d/set-style! context-menu
+                      :left (str client-x "px")
+                      :top (str (+ scroll-y client-y) "px"))))
+     10)))
 
 (defn parse-config
   "Parse configuration from file `content` such as from config.edn."