Skip to content

Commit

Permalink
fix: setToolPassive should not override other bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
sedghi authored and swederik committed Mar 22, 2022
1 parent d5fdc7c commit 0a3b3d0
Showing 1 changed file with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,15 @@ function createToolGroup(toolGroupId: string): IToolGroup | undefined {
return
}

// Would only need this for sanity check if not instantiating/hydrating
// const tool = this.toolOptions[toolName];
const toolModeOptionsWithMode = Object.assign(
{
bindings: [],
},
toolModeOptions,
{
mode: Active,
}
)
const prevBindings = this.toolOptions[toolName]
? this.toolOptions[toolName].bindings
: []

// We should not override the bindings if they are already set
const toolModeOptionsWithMode = {
bindings: [...prevBindings, ...toolModeOptions.bindings],
mode: Active,
}

this.toolOptions[toolName] = toolModeOptionsWithMode
this._toolInstances[toolName].mode = Active
Expand All @@ -177,20 +175,34 @@ function createToolGroup(toolGroupId: string): IToolGroup | undefined {
return
}

// Would only need this for sanity check if not instantiating/hydrating
// const tool = this.toolOptions[toolName];
const toolModeOptionsWithMode = Object.assign(
// Wwe should only remove the primary button bindings and keep
// the other ones (Zoom on right click)
const toolOptions = Object.assign(
{
bindings: [],
bindings: this.toolOptions[toolName]
? this.toolOptions[toolName].bindings
: [],
},
toolModeOptions,
{
mode: Passive,
}
)

this.toolOptions[toolName] = toolModeOptionsWithMode
this._toolInstances[toolName].mode = Passive
// Remove the primary button bindings if they exist
toolOptions.bindings = toolOptions.bindings.filter(
(binding) => binding.mouseButton !== ToolBindings.Mouse.Primary
)

// If there are other bindings, set the tool to be active
let mode = Passive
if (toolOptions.bindings.length !== 0) {
mode = Active
toolOptions.mode = mode
}

this.toolOptions[toolName] = toolOptions
this._toolInstances[toolName].mode = mode
this.refreshViewports()
},
setToolEnabled: function (
Expand Down

0 comments on commit 0a3b3d0

Please sign in to comment.