From d82c541464ef52c009f188f19d114b685ed4f4d5 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Thu, 17 Feb 2022 02:28:02 +0100 Subject: [PATCH] [fixes #358] Implement deselection in RocketPanel multi-select --- .../net/sf/openrocket/gui/scalefigure/RocketPanel.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index b9dddc747..551944835 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -535,12 +535,16 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change // If the shift-button is held, add a newly clicked component to the selection path if ((event.isShiftDown() || event.isMetaDown()) && event.getClickCount() == 1) { List paths = new ArrayList<>(Arrays.asList(selectionModel.getSelectionPaths())); - for (RocketComponent component : clicked) { - if (!selectedComponents.contains(component)) { - TreePath path = ComponentTreeModel.makeTreePath(component); + for (int i = 0; i < clicked.length; i++) { + if (!selectedComponents.contains(clicked[i])) { + TreePath path = ComponentTreeModel.makeTreePath(clicked[i]); paths.add(path); break; } + // If all the clicked components are already in the selection, then deselect an object + if (i == clicked.length - 1) { + paths.removeIf(path -> path.getLastPathComponent() == clicked[0]); + } } selectionModel.setSelectionPaths(paths.toArray(new TreePath[0])); }