From 43ac4ef67695ed6bb95dead163f0ec2e764cd47f Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 6 Nov 2022 06:05:37 +0100 Subject: [PATCH] #6151: Unfocused nodes are added to the focus pool if they end up being selected by other means (programmatically or other features). --- .../selection/RadiantSelectionSystem.cpp | 7 ++++ test/Selection.cpp | 38 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/radiantcore/selection/RadiantSelectionSystem.cpp b/radiantcore/selection/RadiantSelectionSystem.cpp index 08e74d0edd..572a770177 100644 --- a/radiantcore/selection/RadiantSelectionSystem.cpp +++ b/radiantcore/selection/RadiantSelectionSystem.cpp @@ -392,6 +392,13 @@ void RadiantSelectionSystem::onSelectedChanged(const scene::INodePtr& node, cons if (isSelected) { _selection.append(node); + + // Any selectable that is not in the pool yet will be added + // otherwise creating new nodes is making them unselectable + if (_selectionFocusActive) + { + _selectionFocusPool.insert(node); + } } else { diff --git a/test/Selection.cpp b/test/Selection.cpp index 947413db82..8eaf41191f 100644 --- a/test/Selection.cpp +++ b/test/Selection.cpp @@ -1589,4 +1589,42 @@ TEST_F(OrthoViewSelectionTest, ToggleSelectGroupItemInFocusMode) expectNodeSelectionStatus({ brush, brush2 }, { brush3 }); } +// Selecting a node that is not part of the selection focus will add it to the focused set + +TEST_F(OrthoViewSelectionTest, UnfocusedNodeIsAddedToFocusOnSelection) +{ + loadMap("selection_test2.map"); + + auto worldspawn = GlobalMapModule().findOrInsertWorldspawn(); + auto brush = algorithm::findFirstBrushWithMaterial(worldspawn, "textures/numbers/2"); + auto funcStaticTop = algorithm::getEntityByName(GlobalMapModule().getRoot(), "func_static_top"); + + // Select the func_static and enter focus mode + Node_setSelected(funcStaticTop, true); + GlobalSelectionSystem().toggleSelectionFocus(); + + auto originalFocusBounds = GlobalSelectionSystem().getSelectionFocusBounds(); + + // Try to perform selecting the brush + performPointSelectionOnNodePosition(brush, selection::SelectionSystem::eToggle); + + EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0) << "Still nothing should be selected"; + EXPECT_FALSE(Node_isSelected(brush)) << "Selection should not have succeeded"; + + // Programmatically select the node, this adds it to the pool + Node_setSelected(brush, true); + Node_setSelected(brush, false); + + // This point selection ought to succeed now + performPointSelectionOnNodePosition(brush, selection::SelectionSystem::eToggle); + + EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1) << "Brush should be selected now"; + EXPECT_TRUE(Node_isSelected(brush)) << "Selection should have succeeded"; + + auto newFocusBounds = GlobalSelectionSystem().getSelectionFocusBounds(); + + EXPECT_FALSE(math::isNear(originalFocusBounds.getOrigin(), newFocusBounds.getOrigin(), 20)) << "Bound should have been changed"; + EXPECT_FALSE(math::isNear(originalFocusBounds.getExtents(), newFocusBounds.getExtents(), 10)) << "Bounds should have changed form"; +} + }