mirror of https://github.com/logseq/logseq
Simply editor save logic
Triggers save-current-block! on-blur instead of relying on react lifecycle.pull/10793/head
parent
5cad97c617
commit
b50145be4e
|
@ -2496,9 +2496,9 @@
|
||||||
:format format
|
:format format
|
||||||
:on-hide (fn [value event]
|
:on-hide (fn [value event]
|
||||||
(when (= event :esc)
|
(when (= event :esc)
|
||||||
(editor-handler/save-block! (editor-handler/get-state) value)
|
(p/let [_ (editor-handler/save-block! (editor-handler/get-state) value)]
|
||||||
(let [select? (not (string/includes? value "```"))]
|
(let [select? (not (string/includes? value "```"))]
|
||||||
(editor-handler/escape-editing select?))))}
|
(editor-handler/escape-editing select?)))))}
|
||||||
edit-input-id
|
edit-input-id
|
||||||
config))]
|
config))]
|
||||||
(if (and named? (seq (:block/tags block)) db-based?)
|
(if (and named? (seq (:block/tags block)) db-based?)
|
||||||
|
|
|
@ -736,6 +736,7 @@
|
||||||
:on-click (editor-handler/editor-on-click! id)
|
:on-click (editor-handler/editor-on-click! id)
|
||||||
:on-change (editor-handler/editor-on-change! block id search-timeout)
|
:on-change (editor-handler/editor-on-change! block id search-timeout)
|
||||||
:on-paste (paste-handler/editor-on-paste! id)
|
:on-paste (paste-handler/editor-on-paste! id)
|
||||||
|
:on-blur (fn [] (editor-handler/save-current-block!))
|
||||||
:auto-focus false
|
:auto-focus false
|
||||||
:class heading-class}
|
:class heading-class}
|
||||||
(some? parent-block)
|
(some? parent-block)
|
||||||
|
|
|
@ -281,7 +281,6 @@
|
||||||
(when-not (and (:create-today-journal? tx-meta)
|
(when-not (and (:create-today-journal? tx-meta)
|
||||||
(:today-journal-name tx-meta)
|
(:today-journal-name tx-meta)
|
||||||
(d/entity @conn [:block/name (:today-journal-name tx-meta)])) ; today journal created already
|
(d/entity @conn [:block/name (:today-journal-name tx-meta)])) ; today journal created already
|
||||||
;; (prn :debug :transact :tx-data tx-data :tx-meta tx-meta')
|
|
||||||
(worker-util/profile "Worker db transact"
|
(worker-util/profile "Worker db transact"
|
||||||
(ldb/transact! conn tx-data tx-meta')))
|
(ldb/transact! conn tx-data tx-meta')))
|
||||||
nil)
|
nil)
|
||||||
|
|
|
@ -32,9 +32,7 @@
|
||||||
:else
|
:else
|
||||||
(let [{:keys [on-hide value]} (editor-handler/get-state)]
|
(let [{:keys [on-hide value]} (editor-handler/get-state)]
|
||||||
(when on-hide
|
(when on-hide
|
||||||
(on-hide value event))
|
(on-hide value event)))))
|
||||||
(when (contains? #{:esc :visibilitychange :click} event)
|
|
||||||
(state/clear-edit!)))))
|
|
||||||
:node (gdom/getElement id)
|
:node (gdom/getElement id)
|
||||||
;; :visibilitychange? true
|
;; :visibilitychange? true
|
||||||
)))
|
)))
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
(ns ^:no-doc frontend.handler.editor.lifecycle
|
(ns ^:no-doc frontend.handler.editor.lifecycle
|
||||||
(:require [frontend.handler.editor :as editor-handler :refer [get-state]]
|
(:require [frontend.handler.editor :as editor-handler]
|
||||||
[frontend.handler.editor.keyboards :as keyboards-handler]
|
[frontend.handler.editor.keyboards :as keyboards-handler]
|
||||||
[frontend.state :as state]
|
[frontend.state :as state]
|
||||||
[frontend.util :as util]
|
[frontend.util :as util]
|
||||||
[frontend.util.cursor :as cursor]
|
[frontend.util.cursor :as cursor]
|
||||||
[goog.dom :as gdom]
|
[goog.dom :as gdom]))
|
||||||
[frontend.db :as db]))
|
|
||||||
|
|
||||||
(defn did-mount!
|
(defn did-mount!
|
||||||
[state]
|
[state]
|
||||||
|
@ -38,15 +37,7 @@
|
||||||
|
|
||||||
(defn will-unmount
|
(defn will-unmount
|
||||||
[state]
|
[state]
|
||||||
(let [{:keys [value]} (get-state)]
|
(editor-handler/clear-when-saved!)
|
||||||
(editor-handler/clear-when-saved!)
|
|
||||||
(when (and
|
|
||||||
(not (contains? #{:insert :indent-outdent :auto-save :undo :redo :delete} (state/get-editor-op)))
|
|
||||||
;; Don't trigger auto-save if the latest op is undo or redo
|
|
||||||
(not (contains? #{:delete :undo :redo :paste-blocks} (state/get-editor-latest-op))))
|
|
||||||
(let [state (get-state)]
|
|
||||||
(when (db/entity [:block/uuid (:block/uuid (:block state))]) ; block still exists
|
|
||||||
(editor-handler/save-block! state value)))))
|
|
||||||
state)
|
state)
|
||||||
|
|
||||||
(def lifecycle
|
(def lifecycle
|
||||||
|
|
Loading…
Reference in New Issue