Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(): Inconsistency of events when more buttons are used #10143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## [next]

## [6.4.2]

- Fix(): Inconsistency of events when more buttons are used [#10027](https://github.com/fabricjs/fabric.js/issues/10027)
- Fix(): path parsing performance [#10123](https://github.com/fabricjs/fabric.js/pull/10123)

## [6.4.1]
Expand Down
34 changes: 12 additions & 22 deletions src/canvas/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,19 @@ export class Canvas extends SelectableCanvas implements CanvasOptions {
this._onMouseDown as EventListener,
);
}

_checkMouseClick(e: MouseEvent) {
const button = e.button;
if (button == 1) return this.fireMiddleClick
if (button == 2) return this.fireRightClick
return true;
}
/**
* @private
* @param {Event} e Event object fired on mousedown
*/
_onMouseDown(e: TPointerEvent) {
const b = this._checkMouseClick(e as MouseEvent);
if (!b) return;
this.__onMouseDown(e);
this._resetTransformEventData();
const canvasElement = this.upperCanvasEl,
Expand Down Expand Up @@ -697,6 +704,8 @@ export class Canvas extends SelectableCanvas implements CanvasOptions {
* @param {Event} e Event object fired on mouseup
*/
_onMouseUp(e: TPointerEvent) {
const b = this._checkMouseClick(e as MouseEvent);
if (!b) return;
this.__onMouseUp(e);
this._resetTransformEventData();
const canvasElement = this.upperCanvasEl,
Expand Down Expand Up @@ -728,6 +737,8 @@ export class Canvas extends SelectableCanvas implements CanvasOptions {
* @param {Event} e Event object fired on mousemove
*/
_onMouseMove(e: TPointerEvent) {
const b = this._checkMouseClick(e as MouseEvent);
if (!b) return;
const activeObject = this.getActiveObject();
!this.allowTouchScrolling &&
(!activeObject ||
Expand Down Expand Up @@ -778,17 +789,6 @@ export class Canvas extends SelectableCanvas implements CanvasOptions {
const isClick = this._isClick;
const target = this._target;

// if right/middle click just fire events and return
// target undefined will make the _handleEvent search the target
const { button } = e as MouseEvent;
if (button) {
((this.fireMiddleClick && button === 1) ||
(this.fireRightClick && button === 2)) &&
this._handleEvent(e, 'up');
this._resetTransformEventData();
return;
}

if (this.isDrawingMode && this._isCurrentlyDrawing) {
this._onMouseUpInDrawingMode(e);
return;
Expand Down Expand Up @@ -989,16 +989,6 @@ export class Canvas extends SelectableCanvas implements CanvasOptions {

let target: FabricObject | undefined = this._target;

// if right/middle click just fire events
const { button } = e as MouseEvent;
if (button) {
((this.fireMiddleClick && button === 1) ||
(this.fireRightClick && button === 2)) &&
this._handleEvent(e, 'down');
this._resetTransformEventData();
return;
}

if (this.isDrawingMode) {
this._onMouseDownInDrawingMode(e);
return;
Expand Down