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:
Andelf
2021-12-19 13:15:19 +08:00
committed by Tienson Qin
parent 6d80a1488f
commit 7024e9b4c3
4 changed files with 28 additions and 11 deletions

View File

@@ -2,6 +2,7 @@
(:require [cljs-time.coerce :as tc]
[cljs-time.core :as t]
[clojure.string :as string]
[datascript.core :as dc]
[frontend.components.content :as content]
[frontend.components.lazy-editor :as lazy-editor]
[frontend.components.svg :as svg]
@@ -73,11 +74,12 @@
(let [path (get-path state)
format (format/get-format path)
page (db/get-file-page path)
random-id (str (dc/squuid))
config? (= path (config/get-config-path))]
(rum/with-context [[tongue] i18n/*tongue-context*]
[:div.file {:id (str "file-" path)}
[:div.file {:id (str "file-edit-wrapper-" random-id)}
[:h1.title
path]
[:bdi path]]
(when page
[:div.text-sm.mb-4.ml-1 "Page: "
[:a.bg-base-2.p-1.ml-1 {:style {:border-radius 4}
@@ -117,7 +119,11 @@
(let [content (string/trim file-content)
mode (util/get-file-ext path)]
(lazy-editor/editor {:file? true
:file-path path} path {:data-lang mode} content {})))
:file-path path}
(str "file-edit-" random-id)
{:data-lang mode}
content
{})))
:else
[:div (tongue :file/format-not-supported (name format))])])))