Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Mar 2, 2024
1 parent 41e61b4 commit 78facbc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/renderer/document/events.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns renderer.document.events
(:require
[clojure.edn :as edn]
[de-dupe.core :as dd]
#_[de-dupe.core :as dd]
[re-frame.core :as rf]
[re-frame.interceptor :refer [->interceptor get-effect get-coeffect assoc-coeffect assoc-effect]]
[renderer.document.db :as db]
Expand All @@ -14,8 +14,7 @@
(let [db-store-key :re-frame-path/db-store]
(->interceptor
:id :active-document-path
:before (fn
[context]
:before (fn [context]
(let [original-db (get-coeffect context :db)]
(-> context
(update db-store-key conj original-db)
Expand Down
13 changes: 3 additions & 10 deletions src/renderer/events.cljs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
(ns renderer.events
(:require
[clojure.core.matrix :as mat]
[malli.core :as ma]
[platform]
[re-frame.core :as rf]
[renderer.db :as db]
[renderer.frame.handlers :as frame-h]
[renderer.handlers :as h]
[renderer.tools.base :as tools]
[renderer.utils.local-storage :as local-storage]))
[renderer.utils.local-storage :as local-storage]
[renderer.utils.pointer :as pointer]))

(defn check-and-throw
"Throws an exception if `db` doesn't match the Spec"
Expand Down Expand Up @@ -104,13 +104,6 @@
(fn [db [_]]
(update db :snap? not)))

(defn significant-drag?
[pointer-pos pointer-offset]
(let [threshold 1]
(when (and (vector? pointer-pos) (vector? pointer-offset))
(> (apply max (map abs (mat/sub pointer-pos pointer-offset)))
threshold))))

(rf/reg-event-db
:pointer-event
(fn [{:keys [pointer-offset tool content-rect drag?] :as db}
Expand All @@ -121,7 +114,7 @@
(if (= buttons :right)
db
(-> (if pointer-offset
(if (significant-drag? pointer-pos pointer-offset)
(if (pointer/significant-drag? pointer-pos pointer-offset)
(cond-> db
(not= tool :pan)
(frame-h/pan-out-of-canvas content-rect
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/utils/pointer.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns renderer.utils.pointer
(:require
[clojure.core.matrix :as mat]
[re-frame.core :as rf]))

(defn ctrl?
Expand All @@ -14,6 +15,13 @@
[e]
(some #(contains? (:modifiers e) %) #{:ctrl :shift}))

(defn significant-drag?
[pointer-pos pointer-offset]
(let [threshold 1]
(when (and (vector? pointer-pos) (vector? pointer-offset))
(> (apply max (map abs (mat/sub pointer-pos pointer-offset)))
threshold))))

(def button
"https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button"
[:left
Expand Down

0 comments on commit 78facbc

Please sign in to comment.