Skip to content

Commit

Permalink
Use arrow keys to change selection
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhanshuguptagit committed Jun 20, 2024
1 parent 174a70d commit 2bf4437
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/bean/ui/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@
(fn handle-global-kbd [{:keys [db]} [_ e]]
(let [selection (get-in db [:ui :grid :selection])]
(when-let [[r c] (:start selection)]
(if (or (= (.-key e) "Backspace")
(= (.-key e) "Delete"))
{:db (update-in db [:sheet] #(grid/clear-selection % selection))}
(if (= (count (.-key e)) 1)
{:fx [[:dispatch [::edit-cell [r c] (.-key e)]]]}
{:fx [[:dispatch [::edit-cell [r c]]]]}))))))
(let [[mr mc] (get-in db [:sheet :grid r c :style :merged-until])]
(if (or (= (.-key e) "Backspace")
(= (.-key e) "Delete"))
{:db (update-in db [:sheet] #(grid/clear-selection % selection))}
(if-let [move-to (cond
(= (.-key e) "ArrowUp") [(dec r) c]
(= (.-key e) "ArrowLeft") [r (dec c)]
(= (.-key e) "ArrowDown") [(if mr (inc mr) (inc r)) c]
(= (.-key e) "ArrowRight") [r (if mc (inc mc) (inc c))])]
{:fx [[:dispatch [::set-selection {:start move-to :end move-to}]]]}
(if (= (count (.-key e)) 1)
{:fx [[:dispatch [::edit-cell [r c] (.-key e)]]]}
{:fx [[:dispatch [::edit-cell [r c]]]]}))))))))

(rf/reg-event-fx
::paste-addressed-cells
Expand Down
1 change: 1 addition & 0 deletions src/bean/ui/views/sheet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@
(let [focused-element (.-activeElement js/document)
tag-name (and focused-element (.-tagName focused-element))]
(or (= (.toLowerCase tag-name) "span")
(= (.toLowerCase tag-name) "input")
(= (.toLowerCase tag-name) "textarea"))))

(defn ctrl-or-meta? [e]
Expand Down

0 comments on commit 2bf4437

Please sign in to comment.