Feat(canvas): Replace Rectangle tool with new Shapes tool#9082
Feat(canvas): Replace Rectangle tool with new Shapes tool#9082DustyShoe wants to merge 37 commits into
Conversation
…l-with-Shapes-tool
…l-with-Shapes-tool
…l-with-Shapes-tool
…l-with-Shapes-tool
…l-with-Shapes-tool
…l-with-Shapes-tool
|
I only did a quick test, but it works great and feels really nice to use. While I can't comment on the coding implementation since that's not really my area, from a user perspective it's intuitive and smooth. I'd really like to see these 2 improvements:
Really appreciate it. |
|
@ufuksarp Thank you for trying this PR and giving a feedback.
Seems reasonable. I'll add that.
Not sure how the hotkeys are implemented and if it is possible to cycle through modes with hotkey. |
|
I think if we’re going to implement tool hints from #9117, it would be best to merge it before this one. This way I can add the hints directly without creating an additional PR. |
| return ['modSubtractMask', 'shiftSnap45Degrees', 'spacePan', 'altPickColor']; | ||
| } | ||
|
|
||
| if (st === 'freehand') { | ||
| return shouldQuickSwitchToColorPickerOnAlt('rect', st, pointerDown) | ||
| ? ['modSubtractMask', 'spacePan', 'altPickColor'] | ||
| : ['modSubtractMask', 'spacePan']; | ||
| } | ||
|
|
||
| return shouldTranslateShapeDragOnSpace('rect', st, pointerDown, pointerDown) | ||
| ? ['modSubtractMask', 'shiftLockAspectRatio', 'altScaleFromCenter', 'spaceMoveShape'] | ||
| : ['modSubtractMask', 'shiftLockAspectRatio', 'spacePan', 'altPickColor']; |
There was a problem hiding this comment.
Since we've moved beyond masks for this, we should update modSubtractMask and the related en.json text to be more clear; holding control lets you "Erase"
There was a problem hiding this comment.
Updated. I renamed the internal hint from modSubtractMask to modErase and changed the user-facing label to Erase so it reads correctly for Shapes as well as Lasso. I also updated the associated tests.
| {isShapeSelected && ( | ||
| <Box ms={2} mt="-2px" display="flex" alignItems="center" gap={2}> | ||
| <ToolShapeTypeToggle /> | ||
| </Box> | ||
| )} |
There was a problem hiding this comment.
There was a problem hiding this comment.
Updated. I adjusted the toolbar layout so it behaves as a single non-wrapping row with overflow clipped at the container level. That means when there is not enough horizontal space, the excess content is cut off at the right edge instead of sections overlapping each other.

Summary
This PR replaces the existing Rectangle tool with a new Shapes tool in the canvas toolbar.
It introduces a single Shapes tool with multiple modes in the top toolbar:
The tool supports live preview while drawing, uses the active fill color including alpha, and supports subtractive drawing with
Ctrl/Cmd, including a dedicated subtract cursor. Rect and oval support modifier-based drawing behavior, polygon supports start-point close/highlight behavior and snapping, and drawing continues correctly even when the pointer leaves the canvas.(New) While drawing rects and ovals, holding Space now temporarily switches the interaction from resizing to moving the uncommitted shape, without canceling the draw.
There is some intentional overlap with Lasso, because Shapes can also be used on an active Inpaint Mask layer. That said, Lasso still provides broader mask-oriented behavior: it can create a new mask layer automatically when none exists, and it remains a distinct tool with its own hotkey and dedicated masking workflow. In that sense, the overlap is acceptable: Shapes adds general-purpose filled-shape drawing across raster targets, while Lasso remains the more specialized mask-construction tool.
canvasSettingsSliceandcanvasSliceare both covered by existing schema-based persistence migrations. The newshapeTypefield has a default value, and the canvas object schema change is additive/backward-compatible, so no separate manual migration was needed.QA Instructions
Rect,Oval,Polygon, andFreehand.Ctrl/Cmdwhile drawing each shape type. Confirm the operation becomes subtractive, fully clears pixels regardless of active color alpha, and shows the minus-badge crosshair cursor.Shiftto constrain to a square. HoldAltto draw from center. Start the drag inside the canvas, move outside the canvas bounds, and confirm preview/commit still works. PressEscmid-draw and confirm cancel.Shiftto constrain to a circle. HoldAltto draw from center. Also verify outside-canvas drag continuation andEsccancel.Shiftand verify snapping to horizontal, vertical, and 45-degree directions. PressEscto cancel.Merge Plan
Would be best if we merge #9117 before this one.
Checklist
What's Newcopy (if doing a release after this PR)