feat: add exitModeOnEscape option to exit active modes via Escape key#1612
Merged
feat: add exitModeOnEscape option to exit active modes via Escape key#1612
Conversation
Adds a new global option `exitModeOnEscape` that allows users to exit
any active mode (draw, edit, drag, rotate, remove, cut) by pressing
the Escape key.
Usage:
map.pm.setGlobalOptions({ exitModeOnEscape: true });
- Option is disabled by default for backward compatibility
- Handles all mode types: draw, edit, drag, removal, rotate, and cut
- Includes TypeScript definitions
- Includes comprehensive Cypress E2E tests
Closes #1586
Adds a new global option `finishOnEnter` that allows users to finish
drawing shapes (Line, Polygon) by pressing Enter when enough vertices
are placed.
Also fixes Escape key handling to prevent default browser behavior
(blue focus ring) when exiting modes.
Usage:
map.pm.setGlobalOptions({
exitModeOnEscape: true, // Exit any mode with Escape key
finishOnEnter: true, // Finish drawing with Enter key
});
- finishOnEnter works for Line (2+ vertices) and Polygon (3+ vertices)
- Escape key now prevents default browser behavior when active
- Both options are disabled by default for backward compatibility
- Includes TypeScript definitions
- Includes comprehensive Cypress E2E tests
Related to #1586
Introduces Cypress E2E tests to verify that drawing rectangles and circles can be completed by pressing the Enter key after placing the necessary markers. Also includes tests to ensure that pressing Enter before placing markers does not finish the drawing. Additionally, updates the CircleMarker and Rectangle classes to handle click events more robustly by checking for valid latlng coordinates. - Tests added for rectangle and circle drawing scenarios - Ensures correct behavior when Enter is pressed at various stages of drawing - Enhancements to CircleMarker and Rectangle classes for better event handling
|
Amazing! Thank you very much!! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two new global options for keyboard-based interactions:
exitModeOnEscape- Exit any active mode (draw, edit, drag, rotate, remove, cut) by pressing the Escape keyfinishOnEnter- Finish drawing the current shape by pressing the Enter keyThis implements the feature request from #1586.
Usage
Changes
Escape Key (
exitModeOnEscape)_handleEscapeKey()method to the Keyboard mixin that disables all active modesexitModeOnEscape: falseto default global options (disabled by default for backward compatibility)Enter Key (
finishOnEnter)_handleEnterKey()method to the Keyboard mixin that finishes the current shape_canFinishShape()helper to check if a shape has enough vertices to be finishedfinishOnEnter: falseto default global options (disabled by default for backward compatibility)_finishShape()methods to handle being called without an event objectSupported Shapes for
finishOnEnterNot supported (by design)
TypeScript
Tests
exitModeOnEscapecovering all modesfinishOnEntercovering all supported shapesTest plan
Closes #1586