Jelajahi Sumber

fix: t c not working for git repos

Tienson Qin 4 tahun lalu
induk
melakukan
5d0ecd68b2

+ 2 - 14
src/main/frontend/components/sidebar.cljs

@@ -258,6 +258,7 @@
                         (editor-handler/clear-selection! e)
                         (editor-handler/clear-selection! e)
                         (state/set-selection-start-block! nil))))
                         (state/set-selection-start-block! nil))))
 
 
+     ;; TODO: move to keyboards
      (mixins/on-key-down
      (mixins/on-key-down
       state
       state
       {;; esc
       {;; esc
@@ -275,20 +276,7 @@
        ;; ?
        ;; ?
        191 (fn [state e]
        191 (fn [state e]
              (when-not (util/input? (gobj/get e "target"))
              (when-not (util/input? (gobj/get e "target"))
-               (state/sidebar-add-block! (state/get-current-repo) "help" :help nil)))
-       ;; c
-       67 (fn [state e]
-            (when (and
-                   (string/starts-with? (state/get-current-repo) "https://")
-                   (not (util/input? (gobj/get e "target")))
-                   (not (gobj/get e "shiftKey"))
-                   (not (gobj/get e "ctrlKey"))
-                   (not (gobj/get e "altKey"))
-                   (not (gobj/get e "metaKey")))
-              (when-let [repo-url (state/get-current-repo)]
-                (when-not (state/get-edit-input-id)
-                  (util/stop e)
-                  (state/set-modal! commit/add-commit-message)))))})))
+               (state/sidebar-add-block! (state/get-current-repo) "help" :help nil)))})))
   {:did-mount (fn [state]
   {:did-mount (fn [state]
                 (keyboards/bind-shortcuts!)
                 (keyboards/bind-shortcuts!)
                 state)}
                 state)}

+ 18 - 1
src/main/frontend/handler/git.cljs

@@ -10,7 +10,9 @@
             [frontend.handler.route :as route-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.common :as common-handler]
             [frontend.handler.common :as common-handler]
             [frontend.config :as config]
             [frontend.config :as config]
-            [cljs-time.local :as tl]))
+            [cljs-time.local :as tl]
+            [clojure.string :as string]
+            [goog.object :as gobj]))
 
 
 (defn- set-git-status!
 (defn- set-git-status!
   [repo-url value]
   [repo-url value]
@@ -61,3 +63,18 @@
      (config/get-repo-dir repo-url)
      (config/get-repo-dir repo-url)
      name
      name
      email)))
      email)))
+
+(defn show-commit-modal!
+  [modal]
+  (fn [e]
+    (when (and
+          (string/starts-with? (state/get-current-repo) "https://")
+          (not (util/input? (gobj/get e "target")))
+          (not (gobj/get e "shiftKey"))
+          (not (gobj/get e "ctrlKey"))
+          (not (gobj/get e "altKey"))
+          (not (gobj/get e "metaKey")))
+     (when-let [repo-url (state/get-current-repo)]
+       (when-not (state/get-edit-input-id)
+         (util/stop e)
+         (state/set-modal! modal))))))

+ 1 - 1
src/main/frontend/handler/route.cljs

@@ -116,7 +116,7 @@
                 :path-params {:path path}})))
                 :path-params {:path path}})))
 
 
 (defn toggle-between-page-and-file!
 (defn toggle-between-page-and-file!
-  [state e]
+  [_e]
   (let [current-route (state/get-current-route)]
   (let [current-route (state/get-current-route)]
     (case current-route
     (case current-route
       :home
       :home

+ 6 - 2
src/main/frontend/keyboards.cljs

@@ -6,7 +6,9 @@
             [frontend.handler.search :as search-handler]
             [frontend.handler.search :as search-handler]
             [frontend.handler.config :as config-handler]
             [frontend.handler.config :as config-handler]
             [frontend.handler.repo :as repo-handler]
             [frontend.handler.repo :as repo-handler]
+            [frontend.handler.git :as git-handler]
             [frontend.handler.web.nfs :as nfs-handler]
             [frontend.handler.web.nfs :as nfs-handler]
+            [frontend.components.commit :as commit]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.search :as search]
             [frontend.search :as search]
             [frontend.util :as util]
             [frontend.util :as util]
@@ -26,9 +28,9 @@
 
 
 (defn enable-when-not-editing-mode!
 (defn enable-when-not-editing-mode!
   [f]
   [f]
-  (fn [state e]
+  (fn [e]
     (when-not (state/editing?)
     (when-not (state/editing?)
-      (f state e))))
+      (f e))))
 
 
 (def shortcut state/get-shortcut)
 (def shortcut state/get-shortcut)
 
 
@@ -49,6 +51,8 @@
    [(enable-when-not-editing-mode! ui-handler/toggle-contents!) true]
    [(enable-when-not-editing-mode! ui-handler/toggle-contents!) true]
    (or (shortcut :ui/toggle-between-page-and-file) "s")
    (or (shortcut :ui/toggle-between-page-and-file) "s")
    (enable-when-not-editing-mode! route-handler/toggle-between-page-and-file!)
    (enable-when-not-editing-mode! route-handler/toggle-between-page-and-file!)
+   (or (shortcut :git/commit) "c")
+   [(enable-when-not-editing-mode! (git-handler/show-commit-modal! commit/add-commit-message)) true]
    "tab" (-> (editor-handler/on-tab :right)
    "tab" (-> (editor-handler/on-tab :right)
              enable-when-not-editing-mode!)
              enable-when-not-editing-mode!)
    "shift+tab" (-> (editor-handler/on-tab :left)
    "shift+tab" (-> (editor-handler/on-tab :left)