소스 검색

fix(pdf): friendless break line for pdf selection text

charlie 3 년 전
부모
커밋
999ae327d4
2개의 변경된 파일14개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 2
      src/main/frontend/extensions/pdf/highlights.cljs
  2. 12 1
      src/main/frontend/extensions/pdf/utils.cljs

+ 2 - 2
src/main/frontend/extensions/pdf/highlights.cljs

@@ -122,7 +122,7 @@
                         "copy"
                         (do
                           (util/copy-to-clipboard!
-                            (or (:text content) (.toString selection)))
+                            (or (:text content) (pdf-utils/fix-selection-text-breakline (.toString selection))))
                           (pdf-utils/clear-all-selection))
 
                         "link"
@@ -575,7 +575,7 @@
                              {:id         nil
                               :page       page
                               :position   sc-pos
-                              :content    {:text (.toString selection)}
+                              :content    {:text (pdf-utils/fix-selection-text-breakline (.toString selection))}
                               :properties {}})))]
 
             ;; show ctx menu

+ 12 - 1
src/main/frontend/extensions/pdf/utils.cljs

@@ -4,7 +4,8 @@
             [frontend.util :as util]
             ["/frontend/extensions/pdf/utils" :as js-utils]
             [frontend.db :as front-db]
-            [frontend.loader :refer [load]]))
+            [frontend.loader :refer [load]]
+            [clojure.string :as string]))
 
 (defonce MAX-SCALE 5.0)
 (defonce MIN-SCALE 0.25)
@@ -156,6 +157,16 @@
                      :height (.-height rect)})]
         (optimize-client-reacts rects)))))
 
+(defn fix-selection-text-breakline
+  [text]
+
+  (when-not (string/blank? text)
+    (let [sp "@#~#@"]
+      (-> text
+          (string/replace #"[\r\n]+" sp)
+          (string/replace (str "-" sp) "")
+          (string/replace sp " ")))))
+
 ;; TODO: which viewer instance?
 (defn next-page
   []