Skip to content

Commit

Permalink
Toggle keyboard event handling in the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kimo-k committed Jun 18, 2023
1 parent 4cb9fc1 commit 300c2a2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).

## Unreleased

#### Added

- Option to ignore keyboard input. See #386.

## 1.6.0 (2023-05-04)

#### Changed
Expand Down
4 changes: 3 additions & 1 deletion src/day8/re_frame_10x.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
(defn devtools-outer [opts]
;; Add clear button
;; Filter out different trace types
(let [panel-width% (rf/subscribe [::settings.subs/panel-width%])
(let [handle-keys? (rf/subscribe [::settings.subs/handle-keys?])
panel-width% (rf/subscribe [::settings.subs/panel-width%])
showing? (rf/subscribe [::settings.subs/show-panel?])
dragging? (r/atom false)
window-width (r/atom js/window.innerWidth)
Expand All @@ -46,6 +47,7 @@
(let [tag-name (.-tagName (.-target e))
entering-input? (contains? #{"INPUT" "SELECT" "TEXTAREA"} tag-name)]
(when (and (not entering-input?)
@handle-keys?
(= (.-key e) "h")
(.-ctrlKey e))
(rf/dispatch [::settings.events/user-toggle-panel])
Expand Down
6 changes: 4 additions & 2 deletions src/day8/re_frame_10x/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
(rf/inject-cofx ::local-storage/load {:key "data-path-annotations?" :or false})
(rf/inject-cofx ::local-storage/load {:key "show-event-history" :or true})
(rf/inject-cofx ::local-storage/load {:key "open-new-inspectors?" :or true})
(rf/inject-cofx ::local-storage/load {:key "handle-keys?" :or true})
rf/unwrap]
(fn [{:keys [panel-width-ratio show-panel selected-tab filter-items app-db-json-ml-expansions
external-window? external-window-dimensions show-epoch-traces? using-trace?
ignored-events low-level-trace filtered-view-trace retained-epochs app-db-paths
app-db-follows-events? ambiance syntax-color-scheme categories data-path-annotations?
show-event-history open-new-inspectors?]}
show-event-history open-new-inspectors? handle-keys?]}
{:keys [debug?]}]
{:fx [(when using-trace?
[:dispatch [::settings.events/enable-tracing]])
Expand Down Expand Up @@ -71,7 +72,8 @@
[:dispatch [:global/add-unload-hook]]
[:dispatch [::app-db.events/reagent-id]]
[:dispatch [::settings.events/show-event-history? show-event-history]]
[:dispatch [::settings.events/open-new-inspectors? open-new-inspectors?]]]}))
[:dispatch [::settings.events/open-new-inspectors? open-new-inspectors?]]
[:dispatch [::settings.events/handle-keys? handle-keys?]]]}))

;; Global

Expand Down
8 changes: 7 additions & 1 deletion src/day8/re_frame_10x/panels/settings/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,10 @@
::open-new-inspectors?
[(rf/path [:settings :open-new-inspectors?]) rf/trim-v (local-storage/save "open-new-inspectors?")]
(fn [_ [open-new-inspectors?]]
open-new-inspectors?))
open-new-inspectors?))

(rf/reg-event-db
::handle-keys?
[(rf/path [:settings :handle-keys?]) rf/trim-v (local-storage/save "handle-keys?")]
(fn [_ [handle-keys?]]
handle-keys?))
8 changes: 7 additions & 1 deletion src/day8/re_frame_10x/panels/settings/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,10 @@
::open-new-inspectors?
:<- [::root]
(fn [{:keys [open-new-inspectors?]} _]
open-new-inspectors?))
open-new-inspectors?))

(rf/reg-sub
::handle-keys?
:<! [::root]
(fn [{:keys [handle-keys?]} _]
handle-keys?))
9 changes: 9 additions & 0 deletions src/day8/re_frame_10x/panels/settings/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@
:label "nord"
:value :nord
:on-change #(rf/dispatch [::settings.events/set-syntax-color-scheme %])]]])
[rc/line]
(let [handle-keys? (rf/subscribe [::settings.subs/handle-keys?])]
[settings-box
[[rc/checkbox
:model handle-keys?
:label "handle keyboard events"
:on-change #(rf/dispatch [::settings.events/handle-keys? %])]]
[[:p "Should 10x respond to key-press events (such as to open/close the panel)?"]]
settings-box-81])

[rc/line]
(let [ambiance @(rf/subscribe [::settings.subs/ambiance])]
Expand Down

0 comments on commit 300c2a2

Please sign in to comment.