mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 14:41:21 +08:00
[FancyZones] Prevent snapping to invalid zone (#28206)
This commit is contained in:
parent
ebc181bced
commit
2305c8e754
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user