Skip to content

Commit

Permalink
fix: put mouse button check log inside callback to enable dynamically…
Browse files Browse the repository at this point in the history
… change eventTypes
  • Loading branch information
aMoonkin committed Oct 19, 2023
1 parent d80ece2 commit 63877a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
34 changes: 9 additions & 25 deletions packages/x6-plugin-selection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,46 +304,30 @@ export class Selection
}

protected startListening() {
if (this.options.eventTypes?.includes('leftMouseDown')) {
this.graph.on('blank:mousedown', this.onBlankLeftMouseDown, this)
}
if (this.options.eventTypes?.includes('mouseWheelDown')) {
this.graph.on('blank:mousedown', this.onBlankMouseWheelDown, this)
}
this.graph.on('blank:mousedown', this.onBlankMouseDown, this)
this.graph.on('blank:click', this.onBlankClick, this)
this.graph.on('cell:mousemove', this.onCellMouseMove, this)
this.graph.on('cell:mouseup', this.onCellMouseUp, this)
this.selectionImpl.on('box:mousedown', this.onBoxMouseDown, this)
}

protected stopListening() {
if (this.options.eventTypes?.includes('leftMouseDown')) {
this.graph.off('blank:mousedown', this.onBlankLeftMouseDown, this)
}
if (this.options.eventTypes?.includes('mouseWheelDown')) {
this.graph.off('blank:mousedown', this.onBlankMouseWheelDown, this)
}
this.graph.off('blank:mousedown', this.onBlankMouseDown, this)
this.graph.off('blank:click', this.onBlankClick, this)
this.graph.off('cell:mousemove', this.onCellMouseMove, this)
this.graph.off('cell:mouseup', this.onCellMouseUp, this)
this.selectionImpl.off('box:mousedown', this.onBoxMouseDown, this)
}

protected onBlankLeftMouseDown(mouseDownEvent: EventArgs['blank:mousedown']) {
if (mouseDownEvent.e.button === 0) {
this.onBlankMouseDown(mouseDownEvent)
}
}

protected onBlankMouseWheelDown(
mouseDownEvent: EventArgs['blank:mousedown'],
) {
if (mouseDownEvent.e.button === 1) {
this.onBlankMouseDown(mouseDownEvent)
protected onBlankMouseDown({ e }: EventArgs['blank:mousedown']) {
const eventTypes = this.options.eventTypes
if (
!(eventTypes && eventTypes.includes('leftMouseDown') && e.button === 0) &&
!(eventTypes && eventTypes.includes('mouseWheelDown') && e.button === 1)
) {
return
}
}

protected onBlankMouseDown({ e }: EventArgs['blank:mousedown']) {
const allowGraphPanning = this.graph.panning.allowPanning(e, true)
const scroller = this.graph.getPlugin<any>('scroller')
const allowScrollerPanning = scroller && scroller.allowPanning(e, true)
Expand Down
5 changes: 4 additions & 1 deletion packages/x6/src/graph/panning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ export class PanningManager extends Base {

protected onMouseDown({ e }: { e: Dom.MouseDownEvent }) {
const eventTypes = this.widgetOptions.eventTypes
if (!(eventTypes && eventTypes.includes('leftMouseDown'))) {
if (
!(eventTypes && eventTypes.includes('leftMouseDown') && e.button === 0) &&
!(eventTypes && eventTypes.includes('mouseWheelDown') && e.button === 1)
) {
return
}
const selection = this.graph.getPlugin<any>('selection')
Expand Down

0 comments on commit 63877a6

Please sign in to comment.