0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 07:50:43 -05:00

Merge pull request #5171 from penpot/palba-fix-rulers-on-view-only

🐛 Fix you can manage rulers on view mode
This commit is contained in:
Andrey Antukh 2024-10-21 17:29:40 +02:00 committed by GitHub
commit 16e1e01234
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 38 deletions

View file

@ -47,6 +47,7 @@
- Fix problem with caps and inner shadows [Github #4517](https://github.com/penpot/penpot/issues/4517) - Fix problem with caps and inner shadows [Github #4517](https://github.com/penpot/penpot/issues/4517)
- Fix problem with horizontal/vertical lines and shadows [Github #4516](https://github.com/penpot/penpot/issues/4516) - Fix problem with horizontal/vertical lines and shadows [Github #4516](https://github.com/penpot/penpot/issues/4516)
- Fix problem with layers overflowing panel [Taiga #9021](https://tree.taiga.io/project/penpot/issue/9021) - Fix problem with layers overflowing panel [Taiga #9021](https://tree.taiga.io/project/penpot/issue/9021)
- Fix in workspace you can manage rulers on view mode [Taiga #8966](https://tree.taiga.io/project/penpot/issue/8966)
## 2.2.1 ## 2.2.1

View file

@ -18,6 +18,7 @@
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.streams :as ms] [app.main.streams :as ms]
[app.main.ui.context :as ctx]
[app.main.ui.css-cursors :as cur] [app.main.ui.css-cursors :as cur]
[app.main.ui.formats :as fmt] [app.main.ui.formats :as fmt]
[app.main.ui.workspace.viewport.rulers :as rulers] [app.main.ui.workspace.viewport.rulers :as rulers]
@ -56,67 +57,78 @@
snap-pixel? (mf/deref refs/snap-pixel?) snap-pixel? (mf/deref refs/snap-pixel?)
workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)
on-pointer-enter on-pointer-enter
(mf/use-callback (mf/use-callback
(mf/deps workspace-read-only?)
(fn [] (fn []
(st/emit! (dw/set-hover-guide id true)) (when-not workspace-read-only?
(swap! state assoc :hover true))) (st/emit! (dw/set-hover-guide id true))
(swap! state assoc :hover true))))
on-pointer-leave on-pointer-leave
(mf/use-callback (mf/use-callback
(mf/deps workspace-read-only?)
(fn [] (fn []
(st/emit! (dw/set-hover-guide id false)) (when-not workspace-read-only?
(swap! state assoc :hover false))) (st/emit! (dw/set-hover-guide id false))
(swap! state assoc :hover false))))
on-pointer-down on-pointer-down
(mf/use-callback (mf/use-callback
(mf/deps workspace-read-only?)
(fn [event] (fn [event]
(when (= 0 (.-button event)) (when-not workspace-read-only?
(dom/capture-pointer event) (when (= 0 (.-button event))
(mf/set-ref-val! dragging-ref true) (dom/capture-pointer event)
(mf/set-ref-val! start-ref (dom/get-client-position event)) (mf/set-ref-val! dragging-ref true)
(mf/set-ref-val! start-pos-ref (get @ms/mouse-position axis))))) (mf/set-ref-val! start-ref (dom/get-client-position event))
(mf/set-ref-val! start-pos-ref (get @ms/mouse-position axis))))))
on-pointer-up on-pointer-up
(mf/use-callback (mf/use-callback
(mf/deps (select-keys @state [:new-position :new-frame-id]) on-guide-change) (mf/deps (select-keys @state [:new-position :new-frame-id]) on-guide-change workspace-read-only?)
(fn [] (fn []
(when (some? on-guide-change) (when-not workspace-read-only?
(when (some? (:new-position @state)) (when (some? on-guide-change)
(on-guide-change {:position (:new-position @state) (when (some? (:new-position @state))
:frame-id (:new-frame-id @state)}))))) (on-guide-change {:position (:new-position @state)
:frame-id (:new-frame-id @state)}))))))
on-lost-pointer-capture on-lost-pointer-capture
(mf/use-callback (mf/use-callback
(mf/deps workspace-read-only?)
(fn [event] (fn [event]
(dom/release-pointer event) (when-not workspace-read-only?
(mf/set-ref-val! dragging-ref false) (dom/release-pointer event)
(mf/set-ref-val! start-ref nil) (mf/set-ref-val! dragging-ref false)
(mf/set-ref-val! start-pos-ref nil) (mf/set-ref-val! start-ref nil)
(swap! state assoc :new-position nil))) (mf/set-ref-val! start-pos-ref nil)
(swap! state assoc :new-position nil))))
on-pointer-move on-pointer-move
(mf/use-callback (mf/use-callback
(mf/deps position zoom snap-pixel?) (mf/deps position zoom snap-pixel? workspace-read-only?)
(fn [event] (fn [event]
(when-not workspace-read-only?
(when-let [_ (mf/ref-val dragging-ref)]
(let [start-pt (mf/ref-val start-ref)
start-pos (mf/ref-val start-pos-ref)
current-pt (dom/get-client-position event)
delta (/ (- (get current-pt axis) (get start-pt axis)) zoom)
new-position (if (some? position)
(+ position delta)
(+ start-pos delta))
(when-let [_ (mf/ref-val dragging-ref)] new-position (if snap-pixel?
(let [start-pt (mf/ref-val start-ref) (mth/round new-position)
start-pos (mf/ref-val start-pos-ref) new-position)
current-pt (dom/get-client-position event)
delta (/ (- (get current-pt axis) (get start-pt axis)) zoom)
new-position (if (some? position)
(+ position delta)
(+ start-pos delta))
new-position (if snap-pixel? new-frame-id (:id (get-hover-frame))]
(mth/round new-position) (swap! state assoc
new-position) :new-position new-position
:new-frame-id new-frame-id))))))]
new-frame-id (:id (get-hover-frame))]
(swap! state assoc
:new-position new-position
:new-frame-id new-frame-id)))))]
{:on-pointer-enter on-pointer-enter {:on-pointer-enter on-pointer-enter
:on-pointer-leave on-pointer-leave :on-pointer-leave on-pointer-leave
:on-pointer-down on-pointer-down :on-pointer-down on-pointer-down
@ -407,7 +419,8 @@
on-pointer-move on-pointer-move
state state
frame]} frame]}
(use-guide on-guide-change get-hover-frame zoom {:axis axis})] (use-guide on-guide-change get-hover-frame zoom {:axis axis})
workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)]
[:g.new-guides [:g.new-guides
(when-not disabled-guides (when-not disabled-guides
@ -422,7 +435,8 @@
:on-pointer-up on-pointer-up :on-pointer-up on-pointer-up
:on-lost-pointer-capture on-lost-pointer-capture :on-lost-pointer-capture on-lost-pointer-capture
:on-pointer-move on-pointer-move :on-pointer-move on-pointer-move
:class (if (= axis :x) (cur/get-dynamic "resize-ew" 0) (cur/get-dynamic "resize-ns" 0)) :class (when-not workspace-read-only?
(if (= axis :x) (cur/get-dynamic "resize-ew" 0) (cur/get-dynamic "resize-ns" 0)))
:style {:fill "none" :style {:fill "none"
:pointer-events "fill"}}])) :pointer-events "fill"}}]))