Browse Source

fix: use mod+shift+c for raw text copy

Tienson Qin 3 years ago
parent
commit
d49eec78a4

+ 2 - 1
src/main/frontend/handler/common.cljs

@@ -17,7 +17,8 @@
 (defn copy-to-clipboard-without-id-property!
   [format raw-text html]
   (util/copy-to-clipboard! (property/remove-id-property format raw-text))
-  (util/copy-to-clipboard! html true))
+  (when html
+    (util/copy-to-clipboard! html true)))
 
 (defn config-with-document-mode
   [config]

+ 17 - 4
src/main/frontend/handler/editor.cljs

@@ -976,7 +976,7 @@
      (into [] (state/get-export-block-text-remove-options)))))
 
 (defn copy-selection-blocks
-  []
+  [html?]
   (when-let [blocks (seq (state/get-selection-blocks))]
     (let [repo (state/get-current-repo)
           ids (distinct (keep #(when-let [id (dom/attr % "blockid")]
@@ -985,7 +985,7 @@
           block (db/entity [:block/uuid (first ids)])]
       (when block
         (let [html (export/export-blocks-as-html repo ids)]
-          (common-handler/copy-to-clipboard-without-id-property! (:block/format block) content html))
+          (common-handler/copy-to-clipboard-without-id-property! (:block/format block) content (when html? html)))
         (state/set-copied-blocks content ids)
         (notification/show! "Copied!" :success)))))
 
@@ -1054,7 +1054,7 @@
 
 (defn cut-selection-blocks
   [copy?]
-  (when copy? (copy-selection-blocks))
+  (when copy? (copy-selection-blocks true))
   (when-let [blocks (seq (get-selected-blocks))]
     ;; remove embeds, references and queries
     (let [dom-blocks (remove (fn [block]
@@ -2988,7 +2988,7 @@
 
 (defn shortcut-copy-selection
   [_e]
-  (copy-selection-blocks))
+  (copy-selection-blocks true))
 
 (defn shortcut-cut-selection
   [e]
@@ -3036,6 +3036,19 @@
       :else
       (js/document.execCommand "copy"))))
 
+(defn shortcut-copy-text
+  "shortcut copy action:
+  * when in selection mode, copy selected blocks
+  * when in edit mode with text selected, copy selected text as normal"
+  [_e]
+  (when-not (auto-complete?)
+    (cond
+      (state/selection?)
+      (copy-selection-blocks false)
+
+      :else
+      (js/document.execCommand "copy"))))
+
 (defn shortcut-cut
   "shortcut cut action:
   * when in selection mode, cut selected blocks

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

@@ -204,6 +204,9 @@
    :editor/copy                    {:binding "mod+c"
                                     :fn      editor-handler/shortcut-copy}
 
+   :editor/copy-text               {:binding "mod+shift+c"
+                                    :fn      editor-handler/shortcut-copy-text}
+
    :editor/cut                     {:binding "mod+x"
                                     :fn      editor-handler/shortcut-cut}
 
@@ -334,7 +337,7 @@
    :ui/toggle-theme                 {:binding "t t"
                                      :fn      state/toggle-theme!}
 
-   :ui/toggle-contents              {:binding "mod+shift+c"
+   :ui/toggle-contents              {:binding "alt+shift+c"
                                      :fn      ui-handler/toggle-contents!}
 
    :ui/open-new-window              {:binding "mod+n"
@@ -470,6 +473,7 @@
                           :editor/indent
                           :editor/outdent
                           :editor/copy
+                          :editor/copy-text
                           :editor/cut
                           :editor/undo
                           :editor/redo
@@ -541,6 +545,7 @@
     :editor/undo
     :editor/redo
     :editor/copy
+    :editor/copy-text
     :editor/cut]
 
    :shortcut.category/formatting

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

@@ -65,6 +65,7 @@
    :editor/indent                  "Indent block"
    :editor/outdent                 "Outdent block"
    :editor/copy                    "Copy (copies either selection, or block reference)"
+   :editor/copy-text               "Copy selections as text"
    :editor/cut                     "Cut"
    :editor/undo                    "Undo"
    :editor/redo                    "Redo"