소스 검색

feat: type c to git commit

also, fixed an issue that backspace can delete selected blocks
when there's a dialog.
Tienson Qin 4 년 전
부모
커밋
ea9af272e4

+ 16 - 13
src/electron/electron/git.cljs

@@ -71,20 +71,23 @@
 
 (defn add-all-and-commit!
   ([]
-   (add-all-and-commit! "Auto saved by Logseq"))
+   (add-all-and-commit! nil))
   ([message]
-   (->
-    (p/let [_ (init!)
-            _ (add-all!)]
-      (commit! message))
-    (p/catch (fn [error]
-               (when (and (not (string/blank? error))
-                          ;; FIXME: not sure why this happened
-                          (not (string/starts-with? error "fatal: not a git repository")))
-                 (if (string/starts-with? error "Author identity unknown")
-                   (utils/send-to-renderer "setGitUsernameAndEmail" {:type "git"})
-                   (utils/send-to-renderer "notification" {:type "error"
-                                                           :payload error}))))))))
+   (let [message (if (string/blank? message)
+                   "Auto saved by Logseq"
+                   message)]
+     (->
+      (p/let [_ (init!)
+              _ (add-all!)]
+        (commit! message))
+      (p/catch (fn [error]
+                 (when (and (not (string/blank? error))
+                            ;; FIXME: not sure why this happened
+                            (not (string/starts-with? error "fatal: not a git repository")))
+                   (if (string/starts-with? error "Author identity unknown")
+                     (utils/send-to-renderer "setGitUsernameAndEmail" {:type "git"})
+                     (utils/send-to-renderer "notification" {:type "error"
+                                                             :payload error})))))))))
 
 (defonce quotes-regex #"\"[^\"]+\"")
 (defn wrapped-by-quotes?

+ 2 - 2
src/electron/electron/handler.cljs

@@ -209,8 +209,8 @@
   (when (seq args)
     (git/raw! args)))
 
-(defmethod handle :gitCommitAll [_]
-  (git/add-all-and-commit!))
+(defmethod handle :gitCommitAll [_ [_ message]]
+  (git/add-all-and-commit! message))
 
 (defmethod handle :default [args]
   (println "Error: no ipc handler for: " (bean/->js args)))

+ 25 - 26
src/main/frontend/components/commit.cljs

@@ -9,15 +9,18 @@
             [frontend.handler.notification :as notification]
             [promesa.core :as p]
             [goog.dom :as gdom]
-            [goog.object :as gobj]))
+            [goog.object :as gobj]
+            [electron.ipc :as ipc]))
 
 (defn commit-and-push!
   []
   (let [value (gobj/get (gdom/getElement "commit-message") "value")]
     (when (and value (>= (count value) 1))
-      (-> (repo-handler/git-commit-and-push! value)
-          (p/catch (fn [error]
-                     (notification/show! error :error false))))
+      (if (util/electron?)
+        (ipc/ipc "gitCommitAll" value)
+        (-> (repo-handler/git-commit-and-push! value)
+           (p/catch (fn [error]
+                      (notification/show! error :error false)))))
       (state/close-modal!))))
 
 (rum/defcs add-commit-message <
@@ -33,32 +36,28 @@
                       :on-enter (fn []
                                   (commit-and-push!)))))
   [state close-fn]
-  (when-let [repo (state/sub :git/current-repo)]
-    [:div
-     [:div.sm:flex.sm:items-start
-      [:div.mt-3.text-center.sm:mt-0.sm:text-left.mb-2
-       [:h3#modal-headline.text-lg.leading-6.font-medium
-        "Your commit message:"]]]
+  (let [electron? (util/electron?)]
+    (when-let [repo (state/sub :git/current-repo)]
+      [:div.w-full.sm:max-w-lg.sm:w-96
+      [:div.sm:flex.sm:items-start
+       [:div.mt-3.text-center.sm:mt-0.sm:text-left.mb-2
+        [:h3#modal-headline.text-lg.leading-6.font-medium
+         "Your commit message:"]]]
 
-     [:input#commit-message.form-input.block.w-full.sm:text-sm.sm:leading-5.my-2
-      {:auto-focus true
-       :default-value ""}]
+      [:input#commit-message.form-input.block.w-full.sm:text-sm.sm:leading-5.my-2
+       {:auto-focus true
+        :default-value ""}]
 
-     [:div.mt-5.sm:mt-4.sm:flex.sm:flex-row-reverse
-      [:span.flex.w-full.rounded-md.shadow-sm.sm:ml-3.sm:w-auto
-       [:button.inline-flex.justify-center.w-full.rounded-md.border.border-transparent.px-4.py-2.bg-indigo-600.text-base.leading-6.font-medium.text-white.shadow-sm.hover:bg-indigo-500.focus:outline-none.focus:border-indigo-700.focus:shadow-outline-indigo.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
-        {:type "button"
-         :on-click commit-and-push!}
-        "Commit and push!"]]
-      [:span.mt-3.flex.w-full.rounded-md.shadow-sm.sm:mt-0.sm:w-auto
-       [:button.inline-flex.justify-center.w-full.rounded-md.border.border-gray-300.px-4.py-2.bg-white.text-base.leading-6.font-medium.text-gray-700.shadow-sm.hover:text-gray-500.focus:outline-none.focus:border-blue-300.focus:shadow-outline-blue.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
-        {:type "button"
-         :on-click close-fn}
-        "Cancel"]]]]))
+      [:div.mt-5.sm:mt-4.sm:flex.sm:flex-row-reverse
+       [:span.flex.w-full.rounded-md.shadow-sm.sm:ml-3.sm:w-auto
+        [:button.inline-flex.justify-center.w-full.rounded-md.border.border-transparent.px-4.py-2.bg-indigo-600.text-base.leading-6.font-medium.text-white.shadow-sm.hover:bg-indigo-500.focus:outline-none.focus:border-indigo-700.focus:shadow-outline-indigo.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
+         {:type "button"
+          :on-click commit-and-push!}
+         (if electron? "Commit" "Commit and push!")]]]])))
 
 (defn show-commit-modal! [e]
   (when (and
-         (string/starts-with? (state/get-current-repo) "https://")
+         (or (string/starts-with? (state/get-current-repo) "https://") (util/electron?))
          (not (util/input? (gobj/get e "target")))
          (not (gobj/get e "shiftKey"))
          (not (gobj/get e "ctrlKey"))
@@ -67,4 +66,4 @@
     (when-let [repo-url (state/get-current-repo)]
       (when-not (state/get-edit-input-id)
         (util/stop e)
-        (state/set-modal! commit-and-push!)))))
+        (state/set-modal! add-commit-message)))))

+ 1 - 1
src/main/frontend/components/settings.cljs

@@ -202,7 +202,7 @@
   (let [enabled? (not (state/sub [:electron/user-cfgs :git/disable-auto-commit?]))]
     [:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-start
      [:label.block.text-sm.font-medium.leading-5.opacity-70
-      "Git auto commit"]
+      "Enable Git auto commit"]
      [:div
       [:div.rounded-md.sm:max-w-xs
        (ui/toggle

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

@@ -295,7 +295,8 @@
      (mixins/listen state js/window "keydown"
                     (fn [e]
                       (when (= 27 (.-keyCode e))
-                        (hide-context-menu-and-clear-selection))))))
+                        (hide-context-menu-and-clear-selection)
+                        (state/close-modal!))))))
   [state route-match main-content]
   (let [{:keys [open? close-fn open-fn]} state
         close-fn (fn []

+ 1 - 1
src/main/frontend/fs/watcher_handler.cljs

@@ -54,7 +54,7 @@
                (not (string/blank? content))
                (not= (string/trim content)
                      (string/trim (or (db/get-file repo path) ""))))
-          (p/let [result (ipc/ipc "gitCommitAll")
+          (p/let [result (ipc/ipc "gitCommitAll" "")
                   _ (file-handler/alter-file repo path content {:re-render-root? true
                                                                 :from-disk? true})]
             (set-missing-block-ids! content)

+ 1 - 1
src/main/frontend/modules/shortcut/config.cljs

@@ -373,7 +373,7 @@
     ;; :ui/toggle-between-page-and-file route-handler/toggle-between-page-and-file!
     :git/commit
     {:desc    "Git commit message"
-     :binding "g c"
+     :binding "c"
      :fn      commit/show-commit-modal!}}})
 
 

+ 2 - 0
src/main/frontend/state.cljs

@@ -1059,6 +1059,8 @@
   ([modal-panel-content]
    (set-modal! modal-panel-content false))
   ([modal-panel-content fullscreen?]
+   ;; Temporal fix: to avoid deleting selected blocks (backspace in input/textarea)
+   (clear-selection!)
    (swap! state assoc
           :modal/show? (boolean modal-panel-content)
           :modal/panel-content modal-panel-content