mirror of
https://github.com/logseq/logseq.git
synced 2026-05-03 18:36:43 +00:00
feat: more bash-like basic in block editing shortcuts (#1741)
* feat: shortcut for kill line, cursor begin/end, kill block * feat: move or kill by word * fix: off by one * fix: til alt need be avoid on mac * feat: false to disable shortcut * fix: disable more binding for mac * fix: add prevent default for global shortcuts * fix: ctrl+shift+b/f move by word for mac * fix: move backword zero bug
This commit is contained in:
@@ -337,7 +337,7 @@
|
||||
([block value]
|
||||
(save-block-if-changed! block value nil))
|
||||
([block value
|
||||
{:keys []
|
||||
{:keys [force?]
|
||||
:as opts}]
|
||||
(let [{:block/keys [uuid content file page format repo content properties]} block
|
||||
repo (or repo (state/get-current-repo))
|
||||
@@ -352,6 +352,9 @@
|
||||
(util/format "Block with the id % already exists!" block-id)]
|
||||
:error)
|
||||
|
||||
force?
|
||||
(save-block-inner! repo block value opts)
|
||||
|
||||
:else
|
||||
(let [content-changed? (not= (string/trim content) (string/trim value))]
|
||||
(when (and content-changed? page)
|
||||
@@ -1113,7 +1116,7 @@
|
||||
(defn save-current-block!
|
||||
([]
|
||||
(save-current-block! {}))
|
||||
([opts]
|
||||
([{:keys [force?] :as opts}]
|
||||
;; non English input method
|
||||
(when-not (state/editor-in-composition?)
|
||||
(when-let [repo (state/get-current-repo)]
|
||||
@@ -1135,11 +1138,16 @@
|
||||
db-content-without-heading (and db-content
|
||||
(util/safe-subs db-content (:block/level db-block)))
|
||||
value (and elem (gobj/get elem "value"))]
|
||||
(when (and block value db-content-without-heading
|
||||
(or
|
||||
(not= (string/trim db-content-without-heading)
|
||||
(string/trim value))))
|
||||
(save-block-aux! db-block value (:block/format db-block) opts)))
|
||||
(cond
|
||||
force?
|
||||
(save-block-aux! db-block value (:block/format db-block) opts)
|
||||
|
||||
(and block value db-content-without-heading
|
||||
(or
|
||||
(not= (string/trim db-content-without-heading)
|
||||
(string/trim value))))
|
||||
(save-block-aux! db-block value (:block/format db-block) opts))
|
||||
)
|
||||
(catch js/Error error
|
||||
(log/error :save-block-failed error))))))))
|
||||
|
||||
@@ -2545,3 +2553,39 @@
|
||||
|
||||
:else
|
||||
nil))))
|
||||
|
||||
(defn clear-block-content! []
|
||||
(save-current-block! {:force? true})
|
||||
(state/set-edit-content! (state/get-edit-input-id) ""))
|
||||
|
||||
(defn kill-line-before! []
|
||||
(save-current-block! {:force? true})
|
||||
(util/kill-line-before! (state/get-input)))
|
||||
|
||||
(defn kill-line-after! []
|
||||
(save-current-block! {:force? true})
|
||||
(util/kill-line-after! (state/get-input)))
|
||||
|
||||
(defn beginning-of-block []
|
||||
(util/move-cursor-to (state/get-input) 0))
|
||||
|
||||
(defn end-of-block []
|
||||
(util/move-cursor-to-end (state/get-input)))
|
||||
|
||||
(defn cursor-forward-word []
|
||||
(util/move-cursor-forward-by-word (state/get-input)))
|
||||
|
||||
(defn cursor-backward-word []
|
||||
(util/move-cursor-backward-by-word (state/get-input)))
|
||||
|
||||
(defn backward-kill-word []
|
||||
(let [input (state/get-input)]
|
||||
(save-current-block! {:force? true})
|
||||
(util/backward-kill-word input)
|
||||
(state/set-edit-content! (state/get-edit-input-id) (.-value input))))
|
||||
|
||||
(defn forward-kill-word []
|
||||
(let [input (state/get-input)]
|
||||
(save-current-block! {:force? true})
|
||||
(util/forward-kill-word input)
|
||||
(state/set-edit-content! (state/get-edit-input-id) (.-value input))))
|
||||
|
||||
Reference in New Issue
Block a user