From fcda25b110166fa48e9bd6fe046d23877465ac2e Mon Sep 17 00:00:00 2001 From: Jonatan Kronqvist Date: Mon, 2 May 2011 12:51:03 +0000 Subject: [PATCH] Added some explaining comments to a bit of code introduced in the fix for #6841 svn changeset:18583/svn branch:6.6 --- .../vaadin/terminal/gwt/client/ui/VTree.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java index 53ca56aca9..dc60fdc0ad 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java @@ -1804,10 +1804,7 @@ public class VTree extends FocusElementPanel implements Paintable, focusedNode); setFocusedNode(focusedNode.getParentNode()); } else { - TreeNode oldFocusedNode = focusedNode; - setFocusedNode(focusedNode.getParentNode()); - setSelected(focusedNode, true); - setSelected(oldFocusedNode, false); + focusAndSelectNode(focusedNode.getParentNode()); } } return true; @@ -1825,10 +1822,7 @@ public class VTree extends FocusElementPanel implements Paintable, setFocusedNode(focusedNode.getChildren().get(0)); setSelected(focusedNode, true); } else { - TreeNode oldFocusedNode = focusedNode; - setFocusedNode(focusedNode.getChildren().get(0)); - setSelected(focusedNode, true); - setSelected(oldFocusedNode, false); + focusAndSelectNode(focusedNode.getChildren().get(0)); } } return true; @@ -1879,6 +1873,24 @@ public class VTree extends FocusElementPanel implements Paintable, return false; } + private void focusAndSelectNode(TreeNode node) { + /* + * Keyboard navigation doesn't work reliably if the tree is in + * multiselect mode as well as isNullSelectionAllowed = false. It first + * tries to deselect the old focused node, which fails since there must + * be at least one selection. After this the newly focused node is + * selected and we've ended up with two selected nodes even though we + * only navigated with the arrow keys. + * + * Because of this, we first select the next node and later de-select + * the old one. + */ + TreeNode oldFocusedNode = focusedNode; + setFocusedNode(node); + setSelected(focusedNode, true); + setSelected(oldFocusedNode, false); + } + /** * Traverses the tree to the bottom most child * -- 2.39.5