mirror of
https://github.com/logseq/logseq.git
synced 2026-04-29 00:24:51 +00:00
fix(editor): refine file edting, fix state update
- update element state when switching files #3415 - notification when saved - minor style change - refine editor element id gen, use uuid - add trailing newline to saved file Fix #3415
This commit is contained in:
@@ -132,6 +132,7 @@
|
||||
[frontend.extensions.calc :as calc]
|
||||
[frontend.handler.editor :as editor-handler]
|
||||
[frontend.handler.file :as file-handler]
|
||||
[frontend.handler.notification :as notification]
|
||||
[frontend.state :as state]
|
||||
[frontend.utf8 :as utf8]
|
||||
[frontend.util :as util]
|
||||
@@ -170,13 +171,17 @@
|
||||
(:file-path config)
|
||||
(let [path (:file-path config)
|
||||
content (db/get-file-no-sub path)
|
||||
value (some-> (gdom/getElement path)
|
||||
[_ id _ _ _] (:rum/args state)
|
||||
value (some-> (gdom/getElement id)
|
||||
(gobj/get "value"))]
|
||||
(when (and
|
||||
(not (string/blank? value))
|
||||
(not= (string/trim value) (string/trim content)))
|
||||
(file-handler/alter-file (state/get-current-repo) path (string/trim value)
|
||||
{:re-render-root? true})))
|
||||
(file-handler/alter-file (state/get-current-repo)
|
||||
path
|
||||
(str (string/trim value) "\n")
|
||||
{:re-render-root? true})
|
||||
(notification/show! "Saved file!" :success)))
|
||||
|
||||
:else
|
||||
nil))))
|
||||
@@ -267,10 +272,16 @@
|
||||
:did-mount (fn [state]
|
||||
(load-and-render! state)
|
||||
state)
|
||||
:will-update (fn [state]
|
||||
(when-let [editor @(:editor-atom state)]
|
||||
(.toTextArea ^js editor)
|
||||
(let [[_ _ _ code _] (:rum/args state)]
|
||||
(when-let [textarea (rum/ref-node state textarea-ref-name)]
|
||||
(gobj/set textarea "defaultValue" code)
|
||||
(gobj/set textarea "value" code))))
|
||||
state)
|
||||
|
||||
:did-update (fn [state]
|
||||
(when-let [editor @(:editor-atom state)]
|
||||
;; clear the previous instance
|
||||
(.toTextArea ^js editor))
|
||||
(load-and-render! state)
|
||||
state)}
|
||||
[state config id attr code theme options]
|
||||
|
||||
Reference in New Issue
Block a user