RFR: 8324939: Editable TableView loses focus after commit

Andy Goryachev angorya at openjdk.org
Wed Apr 3 18:40:09 UTC 2024


On Wed, 20 Mar 2024 10:55:56 GMT, Jose Pereda <jpereda at openjdk.org> wrote:

> This PR fixes the issue that after committing an edit on a ListView/TreeView/TableView/TreeTableView control, the control might lose the focus unexpectedly.
> 
> For that, it refactors the `ControlUtils::requestFocusOnControlOnlyIfCurrentFocusOwnerIsChild` method, in order to check if the control (`ListView`, `TreeView`, `TableView`, `TreeTableView`) should request the focus _before_ the actual focus owner (which could be the control added to the cell to edit its content, like a `TextField`) is removed from the cell, so the `Control::requestFocus` call, if needed, can be still invoked after the edit commit is done (as it was done before).
> 
> By adding `ControlUtils::controlShouldRequestFocusIfCurrentFocusOwnerIsChild` the `Cell::commitEdit` implementations can now query if the control should have the focus, after `super.commitEdit(newValue);` but before firing the `CellEditEvent` and calling `updateItem()`, and if the result is true, then request focus after the edit commit ends (like it was done before).
> 
> Two new tests per control have been included, to verify that the focus remains at the control, one for edit cancel (this passes before and after the proposed changes), one for edit commit (this fails before and passes after including the proposed fix).

The problem listed in the ticket is fixed, tested on macOS 14.4.1 M1 with the monkey tester.

Thank you for adding tests and fixing the comments!

(there was a comment from @Maran23 , if you would like to address it I'll re-approve).

modules/javafx.controls/src/main/java/javafx/scene/control/TreeCell.java line 429:

> 427: 
> 428:         if (tree != null) {
> 429:             // reset the editing item in the TreeView

+1

-------------

Marked as reviewed by angorya (Reviewer).

PR Review: https://git.openjdk.org/jfx/pull/1411#pullrequestreview-1977641091
PR Review Comment: https://git.openjdk.org/jfx/pull/1411#discussion_r1550251709


More information about the openjfx-dev mailing list