Skip to content

Commit

Permalink
fix: resize sidebar speed with arrow keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc authored and tiensonqin committed Sep 14, 2022
1 parent 79464a5 commit 577f5d2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/frontend/components/right_sidebar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@
min-ratio 0.1
max-ratio 0.7
keyboard-step 5
add-resizing-class #(.. js/document.documentElement -classList (add "is-resizing-buf"))
remove-resizing-class #(.. js/document.documentElement -classList (remove "is-resizing-buf"))
set-width! (fn [ratio element]
(when (and el-ref element)
(let [width (str (* ratio 100) "%")]
Expand Down Expand Up @@ -199,8 +201,8 @@
#(.. js/document.documentElement -classList (remove cursor-class)))
(when (> ratio (/ min-ratio 2)) (state/open-right-sidebar!)))))}}))
(.styleCursor false)
(.on "dragstart" #(.. js/document.documentElement -classList (add "is-resizing-buf")))
(.on "dragend" #(.. js/document.documentElement -classList (remove "is-resizing-buf")))
(.on "dragstart" add-resizing-class)
(.on "dragend" remove-resizing-class)
(.on "keydown" (fn [e]
(when-let [sidebar-el (js/document.getElementById sidebar-id)]
(let [width js/document.documentElement.clientWidth
Expand All @@ -212,7 +214,10 @@
0))
ratio (.toFixed (/ offset width) 6)
ratio (if (= handler-position :west) (- 1 ratio) ratio)]
(when (and (> ratio min-ratio) (< ratio max-ratio)) (set-width! ratio sidebar-el))))))))
(when (and (> ratio min-ratio) (< ratio max-ratio))
((add-resizing-class)
(set-width! ratio sidebar-el)))))))
(.on "keyup" remove-resizing-class)))
#())
[])
[:.resizer {:ref el-ref
Expand Down

0 comments on commit 577f5d2

Please sign in to comment.