🐛 Fix context menu when two elements where selected

This commit is contained in:
Eva 2023-01-16 14:19:23 +01:00 committed by Alonso Torres
parent 1c3470ca53
commit 6fb97e54a9

View file

@ -372,27 +372,25 @@
has-frame? (->> shapes (d/seek cph/frame-shape?)) has-frame? (->> shapes (d/seek cph/frame-shape?))
is-frame? (and single? has-frame?) is-frame? (and single? has-frame?)
is-flex-container? (and is-frame? (= :flex (:layout (first shapes)))) is-flex-container? (and is-frame? (= :flex (:layout (first shapes))))
has-group? (->> shapes (d/seek cph/group-shape?))
is-group? (and single? has-group?)
ids (->> shapes (map :id)) ids (->> shapes (map :id))
add-flex #(st/emit! (if is-frame? add-flex #(st/emit! (if is-frame?
(dwsl/create-layout-from-id ids :flex) (dwsl/create-layout-from-id ids :flex)
(dwsl/create-layout-from-selection :flex))) (dwsl/create-layout-from-selection :flex)))
remove-flex #(st/emit! (dwsl/remove-layout ids))] remove-flex #(st/emit! (dwsl/remove-layout ids))]
(cond
(or single? (and is-frame? (not is-flex-container?)) is-group?)
[:*
[:& menu-separator]
[:& menu-entry {:title (tr "workspace.shape.menu.add-flex")
:shortcut (sc/get-tooltip :toggle-layout-flex)
:on-click add-flex}]]
is-flex-container? [:*
[:* (when (not is-flex-container?)
[:& menu-separator] [:div
[:& menu-entry {:title (tr "workspace.shape.menu.remove-flex") [:& menu-separator]
:shortcut (sc/get-tooltip :toggle-layout-flex) [:& menu-entry {:title (tr "workspace.shape.menu.add-flex")
:on-click remove-flex}]]))) :shortcut (sc/get-tooltip :toggle-layout-flex)
:on-click add-flex}]])
(when is-flex-container?
[:div
[:& menu-separator]
[:& menu-entry {:title (tr "workspace.shape.menu.remove-flex")
:shortcut (sc/get-tooltip :toggle-layout-flex)
:on-click remove-flex}]])]))
(mf/defc context-menu-component (mf/defc context-menu-component
[{:keys [shapes]}] [{:keys [shapes]}]