From d9c9438abffe2797b3a6b37fc97f6049383609b4 Mon Sep 17 00:00:00 2001 From: Charlie Date: Tue, 30 Aug 2022 09:06:45 +0800 Subject: [PATCH] Fix/custom css not reload (#6510) * fix: custom css not reload when switching graph * fix(ux): sometimes code editing auto save not work with blur event --- src/main/frontend/components/file.cljs | 12 ++++++------ src/main/frontend/components/theme.cljs | 2 +- src/main/frontend/extensions/code.cljs | 9 ++++----- src/main/frontend/handler/ui.cljs | 5 +++++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/frontend/components/file.cljs b/src/main/frontend/components/file.cljs index f9b4ee0bc0d..75e261c3669 100644 --- a/src/main/frontend/components/file.cljs +++ b/src/main/frontend/components/file.cljs @@ -103,14 +103,14 @@ [:img {:src path}] (and format (contains? (gp-config/text-formats) format)) - (when-let [file-content (db/get-file path)] + (when-let [file-content (or (db/get-file path) "")] (let [content (string/trim file-content) mode (util/get-file-ext path)] - (lazy-editor/editor {:file? true - :file-path path} - (str "file-edit-" random-id) - {:data-lang mode} - content + (lazy-editor/editor {:file? true + :file-path path} + (str "file-edit-" random-id) + {:data-lang mode} + content {}))) :else diff --git a/src/main/frontend/components/theme.cljs b/src/main/frontend/components/theme.cljs index 1c52edc9bb4..d9e9544370f 100644 --- a/src/main/frontend/components/theme.cljs +++ b/src/main/frontend/components/theme.cljs @@ -47,7 +47,7 @@ (rum/use-effect! (fn [] - (ui-handler/add-style-if-exists!) + (ui-handler/reset-custom-css!) (pdf/reset-current-pdf!) (plugin-handler/hook-plugin-app :current-graph-changed {})) [current-repo]) diff --git a/src/main/frontend/extensions/code.cljs b/src/main/frontend/extensions/code.cljs index 7435e283372..1dbd934c5cd 100644 --- a/src/main/frontend/extensions/code.cljs +++ b/src/main/frontend/extensions/code.cljs @@ -173,10 +173,7 @@ (:file-path config) (let [path (:file-path config) - content (db/get-file path) - [_ id _ _ _] (:rum/args state) - value (some-> (gdom/getElement id) - (gobj/get "value"))] + content (db/get-file path)] (when (and (not (string/blank? value)) (not= (string/trim value) (string/trim content))) @@ -254,7 +251,9 @@ (reset! (:calc-atom state) (calc/eval-lines new-code)))))) (.on editor "blur" (fn [cm e] (when e (util/stop e)) - (when-not (gobj/get cm "escPressed") + (when (or + (= :file (state/get-current-route)) + (not (gobj/get cm "escPressed"))) (save-file-or-block-when-blur-or-esc! editor textarea config state)) (state/set-block-component-editing-mode! false))) (.on editor "focus" (fn [_e] diff --git a/src/main/frontend/handler/ui.cljs b/src/main/frontend/handler/ui.cljs index 35cf6c43e5b..861472996e8 100644 --- a/src/main/frontend/handler/ui.cljs +++ b/src/main/frontend/handler/ui.cljs @@ -124,6 +124,11 @@ ;; (state/get-custom-css-link) )] (util/add-style! style))) +(defn reset-custom-css! + [] + (when-let [el-style (gdom/getElement "logseq-custom-theme-id")] + (dom/remove! el-style)) + (add-style-if-exists!)) (def *js-execed (atom #{}))