mirror of https://github.com/logseq/logseq
Handle files editing without headings
parent
48d4e64aa1
commit
90340e89a7
|
@ -34,7 +34,16 @@
|
||||||
(rum/defcs file < rum/reactive
|
(rum/defcs file < rum/reactive
|
||||||
[state]
|
[state]
|
||||||
(let [[encoded-path path] (get-path state)
|
(let [[encoded-path path] (get-path state)
|
||||||
format (format/get-format path)]
|
format (format/get-format path)
|
||||||
|
save-file-handler (fn [content]
|
||||||
|
(fn [_]
|
||||||
|
(when (handler/file-changed? content)
|
||||||
|
(handler/alter-file (state/get-current-repo) path (state/get-edit-content) nil))))
|
||||||
|
edit-raw-handler (fn []
|
||||||
|
(let [content (db/sub-file path)]
|
||||||
|
(content/content encoded-path {:content content
|
||||||
|
:format format
|
||||||
|
:on-hide (save-file-handler content)})))]
|
||||||
(cond
|
(cond
|
||||||
;; image type
|
;; image type
|
||||||
(and format (contains? (config/img-formats) format))
|
(and format (contains? (config/img-formats) format))
|
||||||
|
@ -42,18 +51,15 @@
|
||||||
|
|
||||||
(and format (contains? config/hiccup-support-formats format))
|
(and format (contains? config/hiccup-support-formats format))
|
||||||
(let [headings (db/get-file-by-concat-headings path)
|
(let [headings (db/get-file-by-concat-headings path)
|
||||||
|
empty-headings? (empty? headings)
|
||||||
headings (db/with-dummy-heading headings format)
|
headings (db/with-dummy-heading headings format)
|
||||||
hiccup (hiccup/->hiccup headings {:id encoded-path})]
|
hiccup (hiccup/->hiccup headings {:id encoded-path})]
|
||||||
(content/content encoded-path {:hiccup hiccup}))
|
(if empty-headings?
|
||||||
|
(edit-raw-handler)
|
||||||
|
(content/content encoded-path {:hiccup hiccup})))
|
||||||
|
|
||||||
(and format (contains? (config/text-formats) format))
|
(and format (contains? (config/text-formats) format))
|
||||||
(let [content (db/sub-file path)]
|
(edit-raw-handler)
|
||||||
(content/content encoded-path
|
|
||||||
{:content content
|
|
||||||
:format format
|
|
||||||
:on-hide (fn []
|
|
||||||
(when (handler/file-changed? content)
|
|
||||||
(handler/alter-file (state/get-current-repo) path (state/get-edit-content) nil)))}))
|
|
||||||
|
|
||||||
:else
|
:else
|
||||||
[:div "Format ." (name format) " is not supported."])))
|
[:div "Format ." (name format) " is not supported."])))
|
||||||
|
|
Loading…
Reference in New Issue