enhance (wip): customizable shortcuts

This commit is contained in:
Konstantinos Kaloutas
2023-04-25 14:06:58 +03:00
committed by Gabriel Horner
parent 9a89def497
commit 96aed148b4
11 changed files with 122 additions and 191 deletions

View File

@@ -10,6 +10,7 @@
[frontend.handler.route :as route-handler]
[frontend.handler.whiteboard :as whiteboard-handler]
[frontend.handler.history :as history]
[frontend.modules.shortcut.data-helper :as shortcut-helper]
[frontend.rum :as r]
[frontend.search :as search]
[frontend.state :as state]
@@ -75,13 +76,18 @@
(apply whiteboard/references-count
(map (fn [k] (js->clj (gobj/get props k) {:keywordize-keys true})) ["id" "className" "options"])))
(rum/defc keyboard-shortcut
[props]
[(ui/render-keyboard-shortcut (shortcut-helper/gen-shortcut-seq (keyword (gobj/get props "action"))))])
(def tldraw-renderers {:Page page-cp
:Block block-cp
:Breadcrumb breadcrumb
:Tweet tweet
:PageName page-name-link
:BacklinksCount references-count
:BlockReference block-reference})
:BlockReference block-reference
:KeyboardShortcut keyboard-shortcut})
(def undo (fn [] (history/undo! nil)))
(def redo (fn [] (history/redo! nil)))

View File

@@ -3159,6 +3159,11 @@
:else
(js/document.execCommand "copy"))))
(defn whiteboard?
[]
(and (state/whiteboard-route?)
(.closest (.-activeElement js/document) ".logseq-tldraw")))
(defn shortcut-cut
"shortcut cut action:
* when in selection mode, cut selected blocks
@@ -3172,14 +3177,24 @@
(and (state/editing?) (util/input-text-selected?
(gdom/getElement (state/get-edit-input-id))))
(keydown-backspace-handler true e)
(whiteboard?)
(.cut (state/active-tldraw-app))
:else
nil))
(defn delete-selection
[e]
(when (state/selection?)
(shortcut-delete-selection e)))
(cond
(state/selection?)
(shortcut-delete-selection e)
(whiteboard?)
(.deleteShapes (.-api ^js (state/active-tldraw-app)))
:else
nil))
(defn editor-delete
[_state e]
@@ -3608,6 +3623,9 @@
edit-block (state/get-edit-block)
target-element (.-nodeName (.-target e))]
(cond
(whiteboard?)
(.selectAll (.-api ^js (state/active-tldraw-app)))
;; editing block fully selected
(and edit-block edit-input
(= (util/get-selected-text) (.-value edit-input)))

View File

@@ -71,6 +71,39 @@
:pdf/find {:binding "alt+f"
:fn pdf-utils/open-finder}
:whiteboard/reset-zoom {:binding "shift+0"
:fn #(.resetZoom (.-api ^js (state/active-tldraw-app)))}
:whiteboard/zoom-to-fit {:binding "shift+1"
:fn #(.zoomToFit (.-api ^js (state/active-tldraw-app)))}
:whiteboard/zoom-to-selection {:binding "shift+2"
:fn #(.zoomToSelection (.-api ^js (state/active-tldraw-app)))}
:whiteboard/collapse {:binding "mod+up"
:fn #(.setCollapsed (.-api ^js (state/active-tldraw-app)) true)}
:whiteboard/expand {:binding "mod+down"
:fn #(.setCollapsed (.-api ^js (state/active-tldraw-app)) false)}
:whiteboard/zoom-out {:binding "mod+-"
:fn #(.zoomOut (.-api ^js (state/active-tldraw-app)) false)}
:whiteboard/zoom-in {:binding "mod+="
:fn #(.zoomIn (.-api ^js (state/active-tldraw-app)) false)}
:whiteboard/send-backward {:binding "["
:fn #(.sendBackward (state/active-tldraw-app))}
:whiteboard/send-to-back {:binding "shift+["
:fn #(.sendToBack (state/active-tldraw-app))}
:whiteboard/bring-forward {:binding "]"
:fn #(.bringForward (state/active-tldraw-app))}
:whiteboard/bring-to-front {:binding "shift+]"
:fn #(.bringToFront (state/active-tldraw-app))}
:whiteboard/lock {:binding "mod+l"
:fn #(.setLocked (state/active-tldraw-app) true)}
@@ -83,7 +116,7 @@
:whiteboard/ungroup {:binding "mod+shift+g"
:fn #(.unGroup (.-api ^js (state/active-tldraw-app)))}
:whiteboard/toggle-grid {:binding "mod+shift+g"
:whiteboard/toggle-grid {:binding "shift g"
:fn #(.toggleGrid (.-api ^js (state/active-tldraw-app)))}
:auto-complete/complete {:binding "enter"
@@ -523,10 +556,21 @@
(with-meta {:before m/enable-when-not-editing-mode!}))
:shortcut.handler/whiteboard
(-> (build-category-map [:whiteboard/lock
(-> (build-category-map [:whiteboard/reset-zoom
:whiteboard/zoom-to-fit
:whiteboard/zoom-to-selection
:whiteboard/collapse
:whiteboard/expand
:whiteboard/send-backward
:whiteboard/send-to-back
:whiteboard/bring-forward
:whiteboard/bring-to-front
:whiteboard/select-all
:whiteboard/lock
:whiteboard/unlock
:whiteboard/group
:whiteboard/ungroup])
:whiteboard/ungroup
:whiteboard/toggle-grid])
(with-meta {:before m/enable-when-not-editing-mode!}))
:shortcut.handler/auto-complete
@@ -781,7 +825,12 @@
:ui/toggle-contents]
:shortcut.category/whiteboard
[:whiteboard/lock
[:whiteboard/reset-zoom
:whiteboard/zoom-to-fit
:whiteboard/zoom-to-selection
:whiteboard/collapse
:whiteboard/expand
:whiteboard/lock
:whiteboard/unlock
:whiteboard/group
:whiteboard/ungroup]

View File

@@ -79,10 +79,21 @@
:editor/zoom-in "Zoom in editing block / Forwards otherwise"
:editor/zoom-out "Zoom out editing block / Backwards otherwise"
:editor/toggle-undo-redo-mode "Toggle undo redo mode (global or page only)"
:whiteboard/lock "Lock selected elements"
:whiteboard/unlock "Unlock selected elements"
:whiteboard/group "Group selected elements"
:whiteboard/ungroup "Ungroup selected elements"
:whiteboard/reset-zoom "Reset zoom"
:whiteboard/zoom-to-fit "Zoom to fit"
:whiteboard/zoom-to-selection "Zoom to fit selection"
:whiteboard/collapse "Collapse selected portals"
:whiteboard/expand "Expand selected portals"
:whiteboard/zoom-out "Zoom out"
:whiteboard/zoom-in "Zoom in"
:whiteboard/send-backward "Move backward"
:whiteboard/send-to-back "Move to back"
:whiteboard/bring-forward "Move forward"
:whiteboard/bring-to-front "Move to front"
:whiteboard/lock "Lock selection"
:whiteboard/unlock "Unlock selection"
:whiteboard/group "Group selection"
:whiteboard/ungroup "Ungroup selection"
:whiteboard/toggle-grid "Toggle the canvas grid"
:ui/toggle-brackets "Toggle whether to display brackets"
:go/search-in-page "Search blocks in the current page"