Skip to content

Implement Backspace key support for polygon/polyline creation#4372

Open
dhruv1955 wants to merge 1 commit intomapeditor:masterfrom
dhruv1955:feature/polygon-backspace-undo
Open

Implement Backspace key support for polygon/polyline creation#4372
dhruv1955 wants to merge 1 commit intomapeditor:masterfrom
dhruv1955:feature/polygon-backspace-undo

Conversation

@dhruv1955
Copy link

Summary

Add Backspace key support to remove the last placed point during polygon
and polyline creation, without canceling the entire shape.

Problem

When drawing polygons or polylines, users had no way to undo just the last
placed point. The only option was Escape, which canceled the entire shape —
forcing a restart even for a single mis-click.

Solution

Handle Qt::Key_Backspace in keyPressed() when state() == CreatingObject:

  • Cancels the operation if only the starting point remains
  • Removes the last point (or first, when extending from the beginning)
  • Creating mode: updates polygon directly via setPolygon()
  • Extending mode: pushes ChangePolygon onto the undo stack for proper history
  • Calls synchronizeOverlayObject() to refresh the visual preview

Changes

  • File: src/tiled/createpolygonobjecttool.cpp
  • Function: keyPressed() — previously only had TODO comments

Testing

  1. Select Insert Polygon tool (P), click 3–4 points, press Backspace — last point removed
  2. Press Backspace repeatedly until 1 point remains — operation cancels
  3. Extend an existing polyline, add points, press Backspace — point removed with undo history entry

Notes

Resolves the first TODO in keyPressed(). The second TODO
(Shift+Enter to finish as polygon) is left for a follow-up.

- Add Backspace key handling in CreatePolygonObjectTool::keyPressed()
- Remove last placed point during polygon/polyline creation
- Support both creating and extending modes
- Update overlay polygon and handles appropriately
- Cancel object when reduced to single point (minimum 2 points required)

Fixes TODO comment about Backspace functionality for going back one step.

Signed-off-by: dhruv1955 <dhruvyadav042905@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant