[FancyZones] Prevent snapping to invalid zone (#28206)

This commit is contained in:
Seraphima Zykova 2023-08-29 19:59:02 +03:00 committed by GitHub
parent ebc181bced
commit 2305c8e754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -124,6 +124,14 @@ bool WorkArea::Snap(HWND window, const ZoneIndexSet& zones, bool updatePosition)
return false;
}
for (ZoneIndex zone : zones)
{
if (static_cast<size_t>(zone) >= m_layout->Zones().size())
{
return false;
}
}
m_layoutWindows.Assign(window, zones);
AppZoneHistory::instance().SetAppLastZones(window, m_uniqueId, m_layout->Id(), zones);

View File

@ -316,6 +316,28 @@ namespace FancyZonesUnitTests
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)
{
const auto workArea = WorkArea::Create(m_hInst, m_workAreaId, m_parentUniqueId, m_workAreaRect);