Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle the deletion of an edited table cell #7552

Merged
merged 1 commit into from Apr 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions editor/src/clj/editor/cljfx_form_view.clj
Expand Up @@ -816,11 +816,21 @@
on-value-changed
ui-state
state-path]}]
(let [indices-path (conj state-path :selected-indices)
selected-indices (set (get-in ui-state indices-path))
(let [{:keys [selected-indices edit] :as state} (get-in ui-state state-path)
selected-indices (set selected-indices)
new-value (remove-indices selected-indices value)]
;; When we remove a row that has been edited, JavaFX will commit the edit.
;; However, by that point, the state will have already changed to a new
;; state without the item that was deleted. This can result in either
;; creating a new row with only one field set (if the deleted row was the
;; last), or applying the edit to the next row after the deleted row (if it
;; wasn't the last). Cancelling the edit here solves the issue.
(when edit
(.edit ^TableView (:table edit) -1 nil))
[[:dispatch (assoc on-value-changed :fx/event new-value)]
[:set-ui-state (assoc-in ui-state indices-path [])]]))
[:set-ui-state (assoc-in ui-state state-path (-> state
(assoc :selected-indices [])
(dissoc :edit)))]]))

(defmethod handle-event :table-select [{:keys [ui-state state-path fx/event]}]
{:set-ui-state (assoc-in ui-state (conj state-path :selected-indices) event)})
Expand Down