Просмотр исходного кода

Shortcut for copying a page url (#8538)

* fix: move primary directory to ~/.config/Logseq

* feat: Add shortcut for copying a page url

* Revert "fix: move primary directory to ~/.config/Logseq"

This reverts commit 1991c60fbf236db93df96e0c0856d73df123a124.

* fix(dev): remove import to pass lint checks

* Address code review

Also
- Add :inactive to command to reflect page-menu platforms like other commands
- Add improved current page like other current file/page commands
- don't use state/sub in non component contexts

---------

Co-authored-by: Gabriel Horner <[email protected]>
sallto 3 лет назад
Родитель
Сommit
bdc11a9dcd

+ 1 - 3
src/main/frontend/components/page_menu.cljs

@@ -10,7 +10,6 @@
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.ui :as ui]
             [frontend.ui :as ui]
             [frontend.util :as util]
             [frontend.util :as util]
-            [frontend.util.url :as url-util]
             [frontend.util.page :as page-util]
             [frontend.util.page :as page-util]
             [frontend.handler.shell :as shell]
             [frontend.handler.shell :as shell]
             [frontend.mobile.util :as mobile-util]
             [frontend.mobile.util :as mobile-util]
@@ -107,8 +106,7 @@
           (when (or (util/electron?)
           (when (or (util/electron?)
                     (mobile-util/native-platform?))
                     (mobile-util/native-platform?))
             {:title   (t :page/copy-page-url)
             {:title   (t :page/copy-page-url)
-             :options {:on-click #(util/copy-to-clipboard!
-                                   (url-util/get-logseq-graph-page-url nil repo page-original-name))}})
+             :options {:on-click #(page-handler/copy-page-url page-original-name)}})
 
 
           (when-not contents?
           (when-not contents?
             {:title   (t :page/delete)
             {:title   (t :page/delete)

+ 21 - 12
src/main/frontend/handler/page.cljs

@@ -9,41 +9,42 @@
             [frontend.context.i18n :refer [t]]
             [frontend.context.i18n :refer [t]]
             [frontend.date :as date]
             [frontend.date :as date]
             [frontend.db :as db]
             [frontend.db :as db]
-            [logseq.db.schema :as db-schema]
+            [frontend.db.conn :as conn]
             [frontend.db.model :as model]
             [frontend.db.model :as model]
             [frontend.db.utils :as db-utils]
             [frontend.db.utils :as db-utils]
-            [frontend.db.conn :as conn]
+            [frontend.format.block :as block]
             [frontend.fs :as fs]
             [frontend.fs :as fs]
             [frontend.handler.common :as common-handler]
             [frontend.handler.common :as common-handler]
+            [frontend.handler.config :as config-handler]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.notification :as notification]
+            [frontend.handler.recent :as recent-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.ui :as ui-handler]
             [frontend.handler.ui :as ui-handler]
             [frontend.handler.web.nfs :as web-nfs]
             [frontend.handler.web.nfs :as web-nfs]
-            [frontend.handler.config :as config-handler]
-            [frontend.handler.recent :as recent-handler]
+            [frontend.mobile.util :as mobile-util]
             [frontend.modules.outliner.core :as outliner-core]
             [frontend.modules.outliner.core :as outliner-core]
             [frontend.modules.outliner.file :as outliner-file]
             [frontend.modules.outliner.file :as outliner-file]
             [frontend.modules.outliner.tree :as outliner-tree]
             [frontend.modules.outliner.tree :as outliner-tree]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.util :as util]
             [frontend.util :as util]
             [frontend.util.cursor :as cursor]
             [frontend.util.cursor :as cursor]
-            [frontend.util.property :as property]
             [frontend.util.fs :as fs-util]
             [frontend.util.fs :as fs-util]
             [frontend.util.page-property :as page-property]
             [frontend.util.page-property :as page-property]
             [frontend.util.page :as page-util]
             [frontend.util.page :as page-util]
+            [frontend.util.property :as property]
+            [frontend.util.url :as url-util]
+            [goog.functions :refer [debounce]]
             [goog.object :as gobj]
             [goog.object :as gobj]
             [lambdaisland.glogi :as log]
             [lambdaisland.glogi :as log]
-            [promesa.core :as p]
-            [frontend.mobile.util :as mobile-util]
-            [logseq.graph-parser.util :as gp-util]
-            [logseq.graph-parser.text :as text]
-            [logseq.graph-parser.config :as gp-config]
+            [logseq.db.schema :as db-schema]
             [logseq.graph-parser.block :as gp-block]
             [logseq.graph-parser.block :as gp-block]
+            [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.property :as gp-property]
             [logseq.graph-parser.property :as gp-property]
+            [logseq.graph-parser.text :as text]
+            [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.util.page-ref :as page-ref]
             [logseq.graph-parser.util.page-ref :as page-ref]
-            [frontend.format.block :as block]
-            [goog.functions :refer [debounce]]))
+            [promesa.core :as p]))
 
 
 ;; FIXME: add whiteboard
 ;; FIXME: add whiteboard
 (defn- get-directory
 (defn- get-directory
@@ -877,3 +878,11 @@
   (if-let [file-path (and (util/electron?) (page-util/get-page-file-path))]
   (if-let [file-path (and (util/electron?) (page-util/get-page-file-path))]
     (js/window.apis.showItemInFolder file-path)
     (js/window.apis.showItemInFolder file-path)
     (notification/show! "No file found" :warning)))
     (notification/show! "No file found" :warning)))
+
+(defn copy-page-url
+  ([] (copy-page-url (page-util/get-current-page-name)))
+  ([page-name]
+   (if page-name
+     (util/copy-to-clipboard!
+      (url-util/get-logseq-graph-page-url nil (state/get-current-repo) page-name))
+     (notification/show! "No page found to copy" :warning))))

+ 6 - 0
src/main/frontend/modules/shortcut/config.cljs

@@ -413,6 +413,10 @@
                                      :inactive (not (util/electron?))
                                      :inactive (not (util/electron?))
                                      :fn      page-handler/copy-current-file}
                                      :fn      page-handler/copy-current-file}
 
 
+   :editor/copy-page-url            {:binding false
+                                     :inactive (not (util/electron?))
+                                     :fn      page-handler/copy-page-url}
+
    :ui/toggle-wide-mode             {:binding "t w"
    :ui/toggle-wide-mode             {:binding "t w"
                                      :fn      ui-handler/toggle-wide-mode!}
                                      :fn      ui-handler/toggle-wide-mode!}
 
 
@@ -626,6 +630,7 @@
                           :editor/open-file-in-default-app
                           :editor/open-file-in-default-app
                           :editor/open-file-in-directory
                           :editor/open-file-in-directory
                           :editor/copy-current-file
                           :editor/copy-current-file
+                          :editor/copy-page-url
                           :editor/new-whiteboard
                           :editor/new-whiteboard
                           :ui/toggle-wide-mode
                           :ui/toggle-wide-mode
                           :ui/select-theme-color
                           :ui/select-theme-color
@@ -769,6 +774,7 @@
     :editor/insert-youtube-timestamp
     :editor/insert-youtube-timestamp
     :editor/open-file-in-default-app
     :editor/open-file-in-default-app
     :editor/open-file-in-directory
     :editor/open-file-in-directory
+    :editor/copy-page-url
     :editor/new-whiteboard
     :editor/new-whiteboard
     :auto-complete/prev
     :auto-complete/prev
     :auto-complete/next
     :auto-complete/next

+ 1 - 0
src/main/frontend/modules/shortcut/dicts.cljc

@@ -122,6 +122,7 @@
    :editor/open-file-in-default-app "Open file in default app"
    :editor/open-file-in-default-app "Open file in default app"
    :editor/open-file-in-directory   "Open file in parent directory"
    :editor/open-file-in-directory   "Open file in parent directory"
    :editor/copy-current-file        "Copy current file"
    :editor/copy-current-file        "Copy current file"
+   :editor/copy-page-url           "Copy page url"
    :ui/toggle-wide-mode             "Toggle wide mode"
    :ui/toggle-wide-mode             "Toggle wide mode"
    :ui/select-theme-color           "Select available theme colors"
    :ui/select-theme-color           "Select available theme colors"
    :ui/goto-plugins                 "Go to plugins dashboard"
    :ui/goto-plugins                 "Go to plugins dashboard"

+ 7 - 0
src/main/frontend/util/page.cljs

@@ -4,6 +4,13 @@
             [frontend.util :as util]
             [frontend.util :as util]
             [frontend.db :as db]))
             [frontend.db :as db]))
 
 
+(defn get-current-page-name
+  "Fetch the current page's original name with same approach as get-current-page-id"
+  []
+  (or (state/get-current-page)
+      (state/get-current-whiteboard)
+      (get-in (first (state/get-editor-args)) [:block :block/page :block/original-name])))
+
 (defn get-current-page-id
 (defn get-current-page-id
   "Fetches the current page id. Looks up page based on latest route and if
   "Fetches the current page id. Looks up page based on latest route and if
   nothing is found, gets page of last edited block"
   nothing is found, gets page of last edited block"