Skip to content

Commit

Permalink
UPDATE: Removed unnecessary if statement, fixed typedefinition for au…
Browse files Browse the repository at this point in the history
…to_panning_event
  • Loading branch information
LotzF committed Feb 11, 2025
1 parent 8367685 commit ff3a4e7
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/LGraphCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ export class LGraphCanvas implements ConnectionColorContext {
auto_panning_threshold: number = 0.95
/** Defines the speed in which the viewport will pan automatic */
auto_panning_speed: number = 350
auto_panning_event: Interval | null = null
auto_panning_event: ReturnType<typeof setInterval> | null = null

getMenuOptions?(): IContextMenuValue[]
getExtraMenuOptions?(
Expand Down Expand Up @@ -1948,29 +1948,27 @@ export class LGraphCanvas implements ConnectionColorContext {
* @remarks Does not require items to be selected to work properly. Could add ramp up/down for smoother movement transition.
* */
autoPanCanvas(deltaT: number): void {
if (this.isDragging || this.connecting_links) {
const moveDirection = getVector2Clamped(
this.mouse,
[this.canvas.clientWidth / 2, this.canvas.clientHeight / 2],
)
if (Math.abs(moveDirection[0]) > this.auto_panning_threshold || Math.abs(moveDirection[1]) > this.auto_panning_threshold) {
const { scale } = this.ds
const newOffsetX: number = (moveDirection[0] * deltaT * this.auto_panning_speed) / scale
const newOffsetY: number = (moveDirection[1] * deltaT * this.auto_panning_speed) / scale
const moveDirection = getVector2Clamped(
this.mouse,
[this.canvas.clientWidth / 2, this.canvas.clientHeight / 2],
)
if (Math.abs(moveDirection[0]) > this.auto_panning_threshold || Math.abs(moveDirection[1]) > this.auto_panning_threshold) {
const { scale } = this.ds
const newOffsetX: number = (moveDirection[0] * deltaT * this.auto_panning_speed) / scale
const newOffsetY: number = (moveDirection[1] * deltaT * this.auto_panning_speed) / scale

this.ds.offset[0] -= newOffsetX
this.ds.offset[1] -= newOffsetY
this.ds.offset[0] -= newOffsetX
this.ds.offset[1] -= newOffsetY

this.#dirty()
if (this.connecting_links) { // Prevent selected Positionables from moving while dragging a link
// Update graph_mouse to prevent link from staying behind while dragging
this.graph_mouse[0] += newOffsetX
this.graph_mouse[1] += newOffsetY
return
}
for (const item of this.selectedItems) {
item.move(newOffsetX, newOffsetY, false)
}
this.#dirty()
if (this.connecting_links) { // Prevent selected Positionables from moving while dragging a link
// Update graph_mouse to prevent link from staying behind while dragging
this.graph_mouse[0] += newOffsetX
this.graph_mouse[1] += newOffsetY
return
}
for (const item of this.selectedItems) {
item.move(newOffsetX, newOffsetY, false)
}
}
}
Expand Down

0 comments on commit ff3a4e7

Please sign in to comment.