Browse Source

fix(editor): wrong file editing save condition

Andelf 2 years ago
parent
commit
3338263088
1 changed files with 7 additions and 4 deletions
  1. 7 4
      src/main/frontend/handler/code.cljs

+ 7 - 4
src/main/frontend/handler/code.cljs

@@ -44,10 +44,13 @@
                   rpath (path/trim-dir-prefix repo-dir path)]
               (if rpath
                 ;; in-db file
-                (let [old-content (or (db/get-file rpath) "")]
-                  (when (and
-                         (not (string/blank? value))
-                         (not= (string/trim value) (string/trim old-content)))
+                (let [db-content (db/get-file rpath)
+                      not-in-db? (nil? db-content)
+                      old-content (or db-content "")
+                      contents-matched? (= (string/trim value) (string/trim old-content))]
+                  (when (or
+                         (and not-in-db? (not-empty value))
+                         (not contents-matched?))
                     (file-handler/alter-file (state/get-current-repo)
                                              rpath
                                              (str (string/trim value) "\n")