feat: mod+enter to create tagged block instead of tagged page

pull/10438/head
Tienson Qin 2023-09-13 22:28:47 +08:00
parent c6a46c43f2
commit 4d10d66735
5 changed files with 45 additions and 31 deletions

View File

@ -733,7 +733,7 @@
true true
(merge (:editor-opts config)))] (merge (:editor-opts config)))]
[:div.editor-inner {:class (if block "block-editor" "non-block-editor")} [:div.editor-inner.flex.flex-1 {:class (if block "block-editor" "non-block-editor")}
(ui/ls-textarea opts) (ui/ls-textarea opts)

View File

@ -266,16 +266,25 @@
(assoc :uuid-changed {:from (:block/uuid block) (assoc :uuid-changed {:from (:block/uuid block)
:to original-uuid})))] :to original-uuid})))]
(outliner-tx/transact! (let [{:keys [tx-data]}
opts' (outliner-tx/transact!
(outliner-core/save-block! block') opts'
;; page properties changed (outliner-core/save-block! block')
(when-let [page-name (and (:block/pre-block? block') ;; page properties changed
(not= original-props (:block/properties block')) (when-let [page-name (and (:block/pre-block? block')
(some-> (:block/page block') :db/id (db-utils/pull) :block/name))] (not= original-props (:block/properties block'))
(state/set-page-properties-changed! page-name))) (some-> (:block/page block') :db/id (db-utils/pull) :block/name))]
(state/set-page-properties-changed! page-name)))
[original linked] (when-not (:insert-block? opts)
(let [original-block (some (fn [m] (and (map? m) (:block/link m) m)) tx-data)]
[original-block (db/entity (:db/id (:block/link original-block)))]))]
;; Block has been tagged, so we need to edit the linked page now
(when (and linked
(= (:block/uuid (state/get-edit-block))
(:block/uuid original)))
(edit-block! linked :max (:block/uuid linked) {})))
;; sanitized page name changed ;; sanitized page name changed
(when-let [title (get-in block' [:block/properties :title])] (when-let [title (get-in block' [:block/properties :title])]
(if (string? title) (if (string? title)
(when-let [old-page-name (:block/name (db/entity (:db/id (:block/page block'))))] (when-let [old-page-name (:block/name (db/entity (:db/id (:block/page block'))))]
@ -351,7 +360,8 @@
(not has-children?))] (not has-children?))]
(outliner-tx/transact! (outliner-tx/transact!
{:outliner-op :insert-blocks} {:outliner-op :insert-blocks}
(save-current-block! {:current-block current-block}) (save-current-block! {:current-block current-block
:insert-block? true})
(outliner-core/insert-blocks! [new-block] current-block {:sibling? sibling? (outliner-core/insert-blocks! [new-block] current-block {:sibling? sibling?
:keep-uuid? keep-uuid? :keep-uuid? keep-uuid?
:replace-empty-target? replace-empty-target?})))) :replace-empty-target? replace-empty-target?}))))
@ -476,10 +486,7 @@
{:ok-handler {:ok-handler
(fn insert-new-block!-ok-handler [last-block] (fn insert-new-block!-ok-handler [last-block]
(clear-when-saved!) (clear-when-saved!)
(edit-block! last-block 0 id) (edit-block! last-block 0 (if original-block (:block/uuid last-block) id)))}))))
(if original-block
(edit-block! last-block 0 (:block/uuid last-block))
(edit-block! last-block 0 id)))}))))
(state/set-editor-op! nil))) (state/set-editor-op! nil)))
(defn api-insert-new-block! (defn api-insert-new-block!
@ -677,19 +684,20 @@
(defn cycle-todo! (defn cycle-todo!
[] []
#_:clj-kondo/ignore #_:clj-kondo/ignore
(if-let [blocks (seq (get-selected-blocks))] (when-not (state/get-editor-action)
(cycle-todos!) (if-let [blocks (seq (get-selected-blocks))]
(when (state/get-edit-block) (cycle-todos!)
(let [edit-input-id (state/get-edit-input-id) (when (state/get-edit-block)
current-input (gdom/getElement edit-input-id) (let [edit-input-id (state/get-edit-input-id)
content (state/get-edit-content) current-input (gdom/getElement edit-input-id)
format (or (db/get-page-format (state/get-current-page)) content (state/get-edit-content)
(state/get-preferred-format)) format (or (db/get-page-format (state/get-current-page))
[new-content marker] (marker/cycle-marker content nil nil format (state/get-preferred-workflow)) (state/get-preferred-format))
new-pos (commands/compute-pos-delta-when-change-marker [new-content marker] (marker/cycle-marker content nil nil format (state/get-preferred-workflow))
content marker (cursor/pos current-input))] new-pos (commands/compute-pos-delta-when-change-marker
(state/set-edit-content! edit-input-id new-content) content marker (cursor/pos current-input))]
(cursor/move-cursor-to current-input new-pos))))) (state/set-edit-content! edit-input-id new-content)
(cursor/move-cursor-to current-input new-pos))))))
(defn set-priority (defn set-priority
[{:block/keys [priority content] :as block} new-priority] [{:block/keys [priority content] :as block} new-priority]

View File

@ -169,9 +169,7 @@
:block/content "" :block/content ""
:block/refs [] :block/refs []
:block/link [:block/uuid (:block/uuid page-m)]}] :block/link [:block/uuid (:block/uuid page-m)]}]
merge-tx))) merge-tx))))))
(state/pub-event! [:editor/edit-block page-m :max (:block/uuid page-m) {}]))))
(reset! (:editor/create-page? @state/state) false))) (reset! (:editor/create-page? @state/state) false)))
(defn rebuild-block-refs (defn rebuild-block-refs

View File

@ -156,6 +156,12 @@
:auto-complete/shift-complete {:binding "shift+enter" :auto-complete/shift-complete {:binding "shift+enter"
:fn ui-handler/auto-complete-shift-complete} :fn ui-handler/auto-complete-shift-complete}
:auto-complete/meta-complete {:binding "mod+enter"
:fn (fn [state e]
(when (= :page-search-hashtag (state/get-editor-action))
(reset! (:editor/create-page? @state/state) false))
(ui-handler/auto-complete-complete state e))}
:auto-complete/open-link {:binding "mod+o" :auto-complete/open-link {:binding "mod+o"
:fn ui-handler/auto-complete-open-link} :fn ui-handler/auto-complete-open-link}
@ -893,6 +899,7 @@
:auto-complete/next :auto-complete/next
:auto-complete/complete :auto-complete/complete
:auto-complete/shift-complete :auto-complete/shift-complete
:auto-complete/meta-complete
:auto-complete/open-link :auto-complete/open-link
:date-picker/prev-day :date-picker/prev-day
:date-picker/next-day :date-picker/next-day

View File

@ -684,6 +684,7 @@
:auto-complete/prev "Auto-complete: Select previous item" :auto-complete/prev "Auto-complete: Select previous item"
:auto-complete/next "Auto-complete: Select next item" :auto-complete/next "Auto-complete: Select next item"
:auto-complete/shift-complete "Auto-complete: Open selected item in sidebar" :auto-complete/shift-complete "Auto-complete: Open selected item in sidebar"
:auto-complete/meta-complete "Auto-complete: Cmd + Enter to choose selected item"
:auto-complete/open-link "Auto-complete: Open selected item in browser" :auto-complete/open-link "Auto-complete: Open selected item in browser"
:cards/toggle-answers "Cards: show/hide answers/clozes" :cards/toggle-answers "Cards: show/hide answers/clozes"
:cards/next-card "Cards: next card" :cards/next-card "Cards: next card"