-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove TargetGridCell from grid move (#6033)
**Problem:** The target grid cell during the move strategy relies on a super ugly singleton variable. **Fix:** Get rid of `TargetGridCell` and instead do the proper adjustments inside the move strategy. **Notes:** - No behavioral changes - The code can be improved further by moving hovering cell data into the editor state (I added a comment in the code) but I left it out of this PR and potentially do it incrementally.
- Loading branch information
Showing
5 changed files
with
73 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
editor/src/components/canvas/canvas-strategies/strategies/grid-helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { WindowPoint } from '../../../../core/shared/math-utils' | ||
import type { GridCellCoordinates } from '../../controls/grid-controls' | ||
import { gridCellCoordinates } from '../../controls/grid-controls' | ||
|
||
export function getGridCellUnderMouse( | ||
windowPoint: WindowPoint, | ||
): { id: string; coordinates: GridCellCoordinates } | null { | ||
const cellsUnderMouse = document | ||
.elementsFromPoint(windowPoint.x, windowPoint.y) | ||
.filter((el) => el.id.startsWith(`gridcell-`)) | ||
if (cellsUnderMouse.length > 0) { | ||
const cellUnderMouse = cellsUnderMouse[0] | ||
const row = cellUnderMouse.getAttribute('data-grid-row') | ||
const column = cellUnderMouse.getAttribute('data-grid-column') | ||
return { | ||
id: cellsUnderMouse[0].id, | ||
coordinates: gridCellCoordinates( | ||
row == null ? 0 : parseInt(row), | ||
column == null ? 0 : parseInt(column), | ||
), | ||
} | ||
} | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters