mirror of
https://github.com/logseq/logseq.git
synced 2026-04-29 00:24:51 +00:00
refactor(fs): handle global file write
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
(ns frontend.handler.code
|
||||
"Codemirror editor related."
|
||||
(:require [frontend.state :as state]
|
||||
[goog.object :as gobj]
|
||||
(:require [clojure.string :as string]
|
||||
[frontend.config :as config]
|
||||
[frontend.db :as db]
|
||||
[frontend.handler.editor :as editor-handler]
|
||||
[frontend.handler.file :as file-handler]
|
||||
[frontend.state :as state]
|
||||
[goog.object :as gobj]
|
||||
[logseq.graph-parser.utf8 :as utf8]
|
||||
[clojure.string :as string]))
|
||||
[frontend.fs2.path :as fs2-path]
|
||||
[frontend.components.content :as content]))
|
||||
|
||||
(defn save-code-editor!
|
||||
[]
|
||||
@@ -20,6 +23,7 @@
|
||||
default-value (gobj/get textarea "defaultValue")]
|
||||
(when (not= value default-value)
|
||||
(cond
|
||||
;; save block content
|
||||
(:block/uuid config)
|
||||
(let [block (db/pull [:block/uuid (:block/uuid config)])
|
||||
content (:block/content block)
|
||||
@@ -34,16 +38,25 @@
|
||||
(state/set-edit-content! (state/get-edit-input-id) new-content)
|
||||
(editor-handler/save-block-if-changed! block new-content))
|
||||
|
||||
(:file-path config)
|
||||
(not-empty (:file-path config))
|
||||
(let [path (:file-path config)
|
||||
content (or (db/get-file path) "")]
|
||||
(when (and
|
||||
(not (string/blank? value))
|
||||
(not= (string/trim value) (string/trim content)))
|
||||
(file-handler/alter-file (state/get-current-repo)
|
||||
path
|
||||
(str (string/trim value) "\n")
|
||||
{:re-render-root? true})))
|
||||
repo (state/get-current-repo)
|
||||
repo-dir (config/get-repo-dir repo)
|
||||
rpath (fs2-path/trim-dir-prefix repo-dir path)
|
||||
;; old-content (db/get-file rpath)
|
||||
_ (prn ::calc rpath)]
|
||||
(if rpath
|
||||
;; in-db file
|
||||
(let [old-content (db/get-file rpath)]
|
||||
(when (and
|
||||
(not (string/blank? value))
|
||||
(not= (string/trim value) (string/trim old-content)))
|
||||
(file-handler/alter-file (state/get-current-repo)
|
||||
rpath
|
||||
(str (string/trim value) "\n")
|
||||
{:re-render-root? true})))
|
||||
;; global file
|
||||
(file-handler/alter-global-file path (str (string/trim value) "\n"))))
|
||||
|
||||
:else
|
||||
nil))))))
|
||||
|
||||
Reference in New Issue
Block a user