浏览代码

fix: resize sidebar speed with arrow keys

Konstantinos Kaloutas 3 年之前
父节点
当前提交
577f5d298b
共有 1 个文件被更改,包括 8 次插入3 次删除
  1. 8 3
      src/main/frontend/components/right_sidebar.cljs

+ 8 - 3
src/main/frontend/components/right_sidebar.cljs

@@ -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) "%")]
@@ -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
@@ -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