Преглед изворни кода

enhance: press Shift to select without entering editor mode

Tienson Qin пре 3 година
родитељ
комит
7d3a536bc8

+ 7 - 1
src/main/frontend/components/block.cljs

@@ -1924,8 +1924,14 @@
         (state/conj-selection-block! (gdom/getElement block-id) :down))
       (when (contains? #{1 0} button)
         (when-not (target-forbidden-edit? target)
-          (if (and shift? (state/get-selection-start-block))
+          (cond
+            (and shift? (state/get-selection-start-block))
             (editor-handler/highlight-selection-area! block-id)
+
+            shift?
+            (util/clear-selection!)
+
+            :else
             (do
               (editor-handler/clear-selection!)
               (editor-handler/unhighlight-blocks!)

+ 7 - 6
src/main/frontend/extensions/html_parser.cljs

@@ -129,12 +129,13 @@
                            :a (let [href (:href attrs)
                                     label (or (map-join children) "")
                                     has-img-tag? (util/safe-re-find #"\[:img" (str x))]
-                                (if has-img-tag?
-                                  (export-hiccup x)
-                                  (case format
-                                    :markdown (util/format "[%s](%s)" label href)
-                                    :org (util/format "[[%s][%s]]" href label)
-                                    nil)))
+                                (when-not (string/blank? href)
+                                  (if has-img-tag?
+                                    (export-hiccup x)
+                                    (case format
+                                      :markdown (util/format "[%s](%s)" label href)
+                                      :org (util/format "[[%s][%s]]" href label)
+                                      nil))))
                            :img (let [src (:src attrs)
                                       alt (or (:alt attrs) "")]
                                   (case format

+ 9 - 16
src/main/frontend/handler/editor.cljs

@@ -2936,35 +2936,28 @@
       :else
       ;; from external
       (let [format (or (db/get-page-format (state/get-current-page)) :markdown)]
+        (util/stop e)
         (match [format
                 (nil? (util/safe-re-find #"(?m)^\s*(?:[-+*]|#+)\s+" text))
                 (nil? (util/safe-re-find #"(?m)^\s*\*+\s+" text))
                 (nil? (util/safe-re-find #"(?:\r?\n){2,}" text))]
           [:markdown false _ _]
-          (do
-            (util/stop e)
-            (paste-text-parseable format text))
+          (paste-text-parseable format text)
 
           [:org _ false _]
-          (do
-            (util/stop e)
-            (paste-text-parseable format text))
+          (paste-text-parseable format text)
 
           [:markdown true _ false]
-          (do
-            (util/stop e)
-            (paste-segmented-text format text))
+          (paste-segmented-text format text)
 
           [:markdown true _ true]
-          nil
+          (commands/simple-insert! (state/get-edit-input-id) text nil)
 
           [:org _ true false]
-          (do
-            (util/stop e)
-            (paste-segmented-text format text))
+          (paste-segmented-text format text)
 
           [:org _ true true]
-          nil)))))
+          (commands/simple-insert! (state/get-edit-input-id) text nil))))))
 
 (defn paste-text-in-one-block-at-point
   []
@@ -2987,7 +2980,7 @@
           edit-block (state/get-edit-block)
           format (or (:block/format edit-block) :markdown)
           initial-text (.getData clipboard-data "text")
-          text (or (when (string/blank? html)
+          text (or (when-not (string/blank? html)
                      (html-parser/convert format html))
                    initial-text)
           input (state/get-input)]
@@ -3215,7 +3208,7 @@
     (state/set-edit-content! (state/get-edit-input-id) (.-value input))))
 
 
-  
+
 (defn block-with-title?
   [format content semantic?]
   (and (string/includes? content "\n")

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

@@ -687,7 +687,8 @@
   (swap! state assoc
          :selection/mode false
          :selection/blocks nil
-         :selection/direction :down))
+         :selection/direction :down
+         :selection/start-block nil))
 
 (defn get-selection-blocks
   []