mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[FancyZones] Prevent snapping to invalid zone (#28206)
This commit is contained in:
@@ -124,6 +124,14 @@ bool WorkArea::Snap(HWND window, const ZoneIndexSet& zones, bool updatePosition)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ZoneIndex zone : zones)
|
||||||
|
{
|
||||||
|
if (static_cast<size_t>(zone) >= m_layout->Zones().size())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_layoutWindows.Assign(window, zones);
|
m_layoutWindows.Assign(window, zones);
|
||||||
AppZoneHistory::instance().SetAppLastZones(window, m_uniqueId, m_layout->Id(), zones);
|
AppZoneHistory::instance().SetAppLastZones(window, m_uniqueId, m_layout->Id(), zones);
|
||||||
|
|
||||||
|
|||||||
@@ -316,6 +316,28 @@ namespace FancyZonesUnitTests
|
|||||||
Assert::IsTrue(expected == layoutWindows.GetZoneIndexSetFromWindow(window));
|
Assert::IsTrue(expected == layoutWindows.GetZoneIndexSetFromWindow(window));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(SnapEmptyZones)
|
||||||
|
{
|
||||||
|
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
|
|
||||||
|
Assert::IsFalse(workArea->Snap(window, {}));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(SnapToIncorrectZone)
|
||||||
|
{
|
||||||
|
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
|
|
||||||
|
const ZoneIndexSet zones = { 10 };
|
||||||
|
Assert::IsFalse(workArea->Snap(window, zones));
|
||||||
|
|
||||||
|
const auto processPath = get_process_path(window);
|
||||||
|
const auto history = AppZoneHistory::instance().GetZoneHistory(processPath, m_workAreaId);
|
||||||
|
|
||||||
|
Assert::IsFalse(history.has_value());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_METHOD (UnsnapPropertyTest)
|
TEST_METHOD (UnsnapPropertyTest)
|
||||||
{
|
{
|
||||||
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|||||||
Reference in New Issue
Block a user