From a7c7fa51cdd061ecaa9397d31c8fb1830490a39b Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 18 Dec 2020 17:14:24 +0800 Subject: [PATCH] fix(editor): rename page will promotes file has been modified Resolved #947 --- src/main/frontend/fs.cljs | 12 ++++++++++-- src/main/frontend/handler/page.cljs | 28 ++++++++++++++-------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main/frontend/fs.cljs b/src/main/frontend/fs.cljs index aca668cbd..9418da6a8 100644 --- a/src/main/frontend/fs.cljs +++ b/src/main/frontend/fs.cljs @@ -181,7 +181,10 @@ ;; :local-last-modified-at local-last-modified-at ;; :not-changed? not-changed? ;; :new-created? new-created? - ;; :pending-writes pending-writes}) + ;; :pending-writes pending-writes + ;; :local-content local-content + ;; :old-content old-content + ;; :new? new?}) (if (and local-content old-content new? (or (> pending-writes 0) @@ -234,10 +237,15 @@ ;; delete old file (p/let [[dir basename] (util/get-dir-and-basename old-path) [_ new-basename] (util/get-dir-and-basename new-path) + parts (->> (string/split new-path "/") + (remove string/blank?)) + dir (str "/" (first parts)) + new-path (->> (rest parts) + (string/join "/")) handle (idb/get-item (str "handle" old-path)) file (.getFile handle) content (.text file) - _ (write-file repo dir new-basename content)] + _ (write-file repo dir new-path content)] (unlink old-path nil)) :else diff --git a/src/main/frontend/handler/page.cljs b/src/main/frontend/handler/page.cljs index 34d78e105..cc527d3e7 100644 --- a/src/main/frontend/handler/page.cljs +++ b/src/main/frontend/handler/page.cljs @@ -294,23 +294,23 @@ (let [repo (state/get-current-repo) old-path (:file/path file) new-path (compute-new-file-path old-path new-name)] + ;; update db + (db/transact! repo [{:db/id (:db/id file) + :file/path new-path}]) + + ;; update files db + (let [conn (db/get-files-conn repo)] + (when-let [file (d/entity (d/db conn) [:file/path old-path])] + (d/transact! conn [{:db/id (:db/id file) + :file/path new-path}]))) (-> (p/let [_ (fs/rename repo (str (util/get-repo-dir repo) "/" old-path) - (str (util/get-repo-dir repo) "/" new-path))] - ;; update db - (db/transact! repo [{:db/id (:db/id file) - :file/path new-path}]) - - ;; update files db - (let [conn (db/get-files-conn repo)] - (when-let [file (d/entity (d/db conn) [:file/path old-path])] - (d/transact! conn [{:db/id (:db/id file) - :file/path new-path}]))) - - (p/let [_ (git/rename repo old-path new-path)] - (common-handler/check-changed-files-status) - (ok-handler))) + (str (util/get-repo-dir repo) "/" new-path)) + _ (when-not (config/local-db? repo) + (git/rename repo old-path new-path))] + (common-handler/check-changed-files-status) + (ok-handler)) (p/catch (fn [error] (println "file rename failed: " error))))))