Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 8, 2025

Closes #XXXX

This PR implements ESC key handling for tile tools, allowing users to cancel ongoing selections or clear existing selections by pressing ESC, improving UX consistency with object selection behavior.

Problem

Previously, users had to either:

  • Click outside the map area, or
  • Use the keyboard shortcut Shift+Cmd+A (Select None)

to clear or cancel tile selections. This was unintuitive and inconsistent with object selection, which has supported ESC since commit 4b3c0a2.

Solution

Added keyPressed method overrides with context-aware, two-level ESC handling:

  1. Cancel ongoing selection - When actively dragging to select (TileSelectionTool only)
  2. Clear existing selection - When a selection exists (works with ANY tile tool, not just selection tools)

This matches the behavior pattern already established in ObjectSelectionTool.

Implementation

AbstractTileTool

Added keyPressed method that clears the selected area when ESC is pressed:

  • Checks if a tile selection exists
  • Creates a ChangeSelectedArea command with an empty region
  • Pushes to undo stack (making the action undoable with Ctrl+Z)

This base implementation automatically benefits ALL tile tools, including:

  • Stamp Brush - Paint tiles
  • Bucket Fill - Fill connected areas
  • Shape Fill - Draw shapes
  • Eraser - Erase tiles
  • TileSelectionTool - Rectangular select
  • MagicWandTool - Select connected similar tiles
  • SelectSameTileTool - Select all instances of a tile
  • Any future tile tools

TileSelectionTool

Extended with custom keyPressed to handle canceling in-progress selections:

  • First checks if actively selecting (dragging with mouse)
  • If yes: Cancels the selection action by resetting state and clearing the brush preview
  • If no: Defers to AbstractTileTool to clear any existing selection

Usage Examples

Scenario User Action Result
While dragging to select Press ESC Selection preview disappears, action cancelled
Using Stamp Brush with selection Press ESC Selection cleared (can undo with Ctrl+Z)
Using Bucket Fill with selection Press ESC Selection cleared
Using Shape Fill with selection Press ESC Selection cleared
Using Magic Wand Press ESC Selection cleared
Using Select Same Tile Press ESC Selection cleared
No selection exists Press ESC Nothing happens

Benefits

  • ✅ Intuitive ESC key behavior matching user expectations
  • ✅ Consistent with object selection tools
  • ✅ Works with ALL tile tools, not just selection tools
  • ✅ Context-aware (cancel vs clear based on state)
  • ✅ Properly integrated with undo/redo system
  • ✅ No breaking changes
  • ✅ Minimal code changes

Fixes #4243

Original prompt

This section details on the original issue you should resolve

<issue_title>[Suggest] press ESC to cancel the selected range.</issue_title>
<issue_description>### Is your feature request related to a problem? Please describe.

If I've used the select rect tool or use CMD+A to select a range on the map , then I want to cancel the select range I have to click somewhere that out of map area of use shift + cmd + a
Sometimes it's not a good way . I hope tiled could support use press ESC key to cancel the selected range.

Describe the solution you'd like.

use press ESC key to cancel the selected range.

Describe alternatives you've considered.

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@bjorn

You can change the keyboard shortcut of Select None from Shift+Cmd+A to Esc in Edit > Preferences > Keyboard.

I wonder if it should do that by default regardless of the bound shortcut, because I think such behavior could be expected based on other applications and it would be consistent with object selection, which also clears on Esc since 4b3c0a2.</comment_new>
<comment_new>@bjorn

I haven't tested the behaviour of object selection Esc, but I'd hope it only works under similar restrictions.

Yes, that handling of Esc is context-sensitive, so you could even press Esc three times and it would do:

  • Cancel object creation
  • Switch back to Select Objects tool
  • Clear object selection

There might be similarly multiple uses of Esc for tile layer related tools, not sure. But we can at least start by handling Esc to clear selection. I'd have to check what happens when one of the actions is also bound to Esc.</comment_new>

Fixes #4243

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI assigned Copilot and bjorn Oct 8, 2025
@Copilot Copilot AI changed the title [WIP] Add support for ESC key to cancel selected range Add ESC key support to cancel/clear tile selections Oct 8, 2025
@Copilot Copilot AI requested a review from bjorn October 8, 2025 18:46
Copilot finished work on behalf of bjorn October 8, 2025 18:46
@bjorn bjorn force-pushed the copilot/add-esc-key-cancel-range-selection branch from 1ea11d1 to 0993d9a Compare October 15, 2025 14:31
@bjorn bjorn force-pushed the copilot/add-esc-key-cancel-range-selection branch from e24e5a4 to 3dd851e Compare October 15, 2025 17:28
@bjorn
Copy link
Member

bjorn commented Oct 15, 2025

@copilot This way, the tile selection can't be cleared using Escape when any other tile-related tool is selected. Hence, please move the handling of Escape to clear the tile selection from the AbstractTileSelectionTool to the AbstractTileTool.

This allows tile selection to be cleared using ESC when any tile-related
tool is selected, not just tile selection tools.

Co-authored-by: bjorn <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 15, 2025

@copilot This way, the tile selection can't be cleared using Escape when any other tile-related tool is selected. Hence, please move the handling of Escape to clear the tile selection from the Abstrac...

Done. Moved the ESC handling to AbstractTileTool so it works with any tile-related tool. Commit: 7e82f73

Copilot finished work on behalf of bjorn October 15, 2025 19:32
@bjorn bjorn marked this pull request as ready for review October 15, 2025 19:41
@bjorn bjorn merged commit 3f3c877 into master Oct 15, 2025
14 of 16 checks passed
@bjorn bjorn deleted the copilot/add-esc-key-cancel-range-selection branch October 15, 2025 20:06
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.

[Suggest] press ESC to cancel the selected range.

2 participants