Right click drag for polygon brush tools#1470
Conversation
|
@mzur The fill/erase/magic wand/brush tools were all triggered with the right mouse button as well, I hope this doesn't break anybody's work flow. If it does we could add additional modifiers like shift + right click for dragging. |
There was a problem hiding this comment.
Pull request overview
Adds a right-click drag pan gesture to the image annotation map while “advanced” polygon tools (polygon brush/eraser/fill, magic wand) are active, so users can move the image without triggering the active tool (Issue #795).
Changes:
- Adds a dedicated
DragPaninteraction that activates on right-mouse-button drag when brush/wand modes are active. - Updates polygon brush/eraser/fill interactions to use a mouse-button-based condition.
- Updates the magic wand interaction to ignore non-matching mouse actions on pointer down.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| resources/assets/js/annotations/ol/MagicWandInteraction.js | Gates magic-wand drawing start based on a mouse-action condition. |
| resources/assets/js/annotations/components/annotationCanvas/polygonBrushInteraction.vue | Changes brush/eraser/fill interaction conditions to use mouseActionButton. |
| resources/assets/js/annotations/components/annotationCanvas/magicWandInteraction.vue | Passes a condition option into the magic wand interaction construction. |
| resources/assets/js/annotations/components/annotationCanvas.vue | Adds right-click drag panning via DragPan and suppresses context menu while active. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| if (e.originalEvent.button === 2) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Maybe implement this as a generic condition similar to the other interactions?
| indicatorPointStyle: Styles.editing, | ||
| indicatorCrossStyle: Styles.cross, | ||
| simplifyTolerant: 0.1, | ||
| simplifyTolerant: 0.1 |
There was a problem hiding this comment.
The codebase prefers trailing commas everywhere.
| simplifyTolerant: 0.1 | |
| simplifyTolerant: 0.1, |
| style: Styles.editing, | ||
| brushRadius: brushRadius, | ||
| resizeCondition: altKeyOnly, | ||
| condition: (event) => event.originalEvent.button !== 2 |
There was a problem hiding this comment.
Maybe we could also use the existing primaryAction condition as "must be something like left click" instead of "must not be right click"? Or we implement a custom rightClick condition (see annotations/ol/events/conditions.js) and (re-)use !rightClick.
Example:
| condition: (event) => event.originalEvent.button !== 2 | |
| condition: primaryAction |
| @@ -283,6 +289,18 @@ export default { | |||
| }, | |||
| })); | |||
|
|
|||
| map.addInteraction(new DragPan({ | |||
| condition: (mapBrowserEvent) => { | |||
| return mapBrowserEvent.originalEvent.button === 2 && noModifierKeys(mapBrowserEvent) && this.isBrushOrWandMode; | |||
| }, | |||
| })); | |||
|
|
|||
| map.getViewport().addEventListener('contextmenu', (e) => { | |||
| if (this.isBrushOrWandMode) { | |||
| e.preventDefault(); | |||
| } | |||
| }); | |||
|
|
|||
There was a problem hiding this comment.
I'd suggest to put this into the polygonBrushInteraction mixin but this wouldn't fit with the magic wand tool. Maybe add a DragPan for the polygon tools and another one for the magic wand interaction? This would repeat code but the separation is cleaner in the different files.
| @@ -653,6 +660,18 @@ export default { | |||
| }), | |||
| }); | |||
|
|
|||
| map.addInteraction(new DragPan({ | |||
| condition: (mapBrowserEvent) => { | |||
| return mapBrowserEvent.originalEvent.button === 2 && noModifierKeys(mapBrowserEvent) && this.isBrushOrWandMode; | |||
| }, | |||
| })); | |||
|
|
|||
| map.getViewport().addEventListener('contextmenu', (e) => { | |||
| if (this.isBrushOrWandMode) { | |||
| e.preventDefault(); | |||
| } | |||
| }); | |||
There was a problem hiding this comment.
Again maybe move this to the mixin files?
| <p> | ||
| When any of the polygon brush/fill/eraser tools or the magic wand tool is active: | ||
| </p> | ||
|
|
||
| <table class="table"> | ||
| <thead> | ||
| <tr> | ||
| <th>Key</th> | ||
| <th>Function</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr> | ||
| <td><kbd>Right click</kbd> (held)</td> | ||
| <td>Drag the map<br></td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
There was a problem hiding this comment.
I'm not sure about this. Some kind of documentation is good but this is not really a keyboard shortcut. Maybe we should rather add a note about it to the manual articles on creating/editing annotations.
| <p> | ||
| When any of the polygon brush/fill/eraser tools or the magic wand tool is active: | ||
| </p> | ||
|
|
||
| <table class="table"> | ||
| <thead> | ||
| <tr> | ||
| <th>Key</th> | ||
| <th>Function</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr> | ||
| <td><kbd>Right click</kbd> (held)</td> | ||
| <td>Drag the map<br></td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
Closes #795