From 999ae327d4434dfc3a48f7aeda8346112b3f209c Mon Sep 17 00:00:00 2001 From: charlie Date: Sun, 24 Jul 2022 17:55:50 +0800 Subject: [PATCH] fix(pdf): friendless break line for pdf selection text --- src/main/frontend/extensions/pdf/highlights.cljs | 4 ++-- src/main/frontend/extensions/pdf/utils.cljs | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/frontend/extensions/pdf/highlights.cljs b/src/main/frontend/extensions/pdf/highlights.cljs index 6b07f749f..04bc0a7b4 100644 --- a/src/main/frontend/extensions/pdf/highlights.cljs +++ b/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 diff --git a/src/main/frontend/extensions/pdf/utils.cljs b/src/main/frontend/extensions/pdf/utils.cljs index 4a28f0f5b..f1dd9be9f 100644 --- a/src/main/frontend/extensions/pdf/utils.cljs +++ b/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 []