Skip to content

Commit

Permalink
Fix cell selection order when editing
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhanshuguptagit committed Jun 20, 2024
1 parent 07906ed commit a0166e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/bean/ui/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@
(rf/reg-event-fx
::submit-cell-input
(fn submit-cell-input [{:keys [db]} [_ content]]
{:fx [[:dispatch [::update-cell (get-in db [:ui :grid :editing-cell]) content]]]}))
(let [editing-cell (get-in db [:ui :grid :editing-cell])]
{:fx [[:dispatch [::clear-edit-cell]]
[:dispatch [::update-cell editing-cell content]]]})))

(rf/reg-event-db
::resize-row
Expand All @@ -140,7 +142,7 @@
::focus-element
(fn [[el-id text]]
(rc/after-render
#(let [el (-> js/document (.getElementById el-id))]
#(when-let [el (-> js/document (.getElementById el-id))]
(when text (set! (.-innerHTML el) text))
(.focus el)
(.selectAllChildren (.getSelection js/window) el)
Expand Down
5 changes: 2 additions & 3 deletions src/bean/ui/views/sheet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

(defn- submit-cell-input []
(when-let [el (.getElementById js/document "cell-input")]
(rf/dispatch [::events/submit-cell-input (str (.-textContent el))])
(rf/dispatch-sync [::events/submit-cell-input (str (.-textContent el))])
;; Reagent does not clear the element when input moves to a blank cell.
(set! (.-innerHTML el) nil)))

Expand Down Expand Up @@ -130,8 +130,7 @@

(defn- cell-pointer-down [rc grid-g sheet row-heights col-widths pixi-app]
(submit-cell-input)
(rf/dispatch [::events/clear-edit-cell])
(rf/dispatch-sync [::events/set-selection {:start rc :end rc}])
(rf/dispatch [::events/set-selection {:start rc :end rc}])
(when (and (< (- (js/Date.now) (:time @last-click)) 300)
(= (:rc @last-click) rc))
(cell-double-click rc sheet))
Expand Down

0 comments on commit a0166e4

Please sign in to comment.