Skip to content

Commit

Permalink
Merge pull request #393 from quadratichq/resize-negative-space-move
Browse files Browse the repository at this point in the history
fix bug with negative heading resizing moving the viewport
  • Loading branch information
davidkircos committed Apr 2, 2023
2 parents d89e02e + f43d7ee commit 4f612dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/grid/sheet/GridOffsets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ export class GridOffsets {
} else {
this.rows.set(change.row, { id: change.row, size: change.size });
}
this.gridOffsetsCache.reset('row', change.row < 0);
} else if (change.column !== undefined) {
const entry = this.columns.get(change.column);
if (entry) {
entry.size = change.size;
} else {
this.columns.set(change.column, { id: change.column, size: change.size });
}
this.gridOffsetsCache.reset('column', change.column < 0);
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/grid/sheet/GridOffsetsCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ export class GridOffsetsCache {
this.rowNegativeCache = [0];
}

reset(direction: 'column' | 'row', negative: boolean) {
if (direction === 'column') {
if (negative) {
this.columnNegativeCache = [0];
} else {
this.columnCache = [0];
}
} else {
if (negative) {
this.rowNegativeCache = [0];
} else {
this.rowCache = [0];
}
}
}

getColumnPlacement(column: number): { x: number; width: number } {
let position = 0;
if (column === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/gridGL/interaction/pointer/PointerHeading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class PointerHeading {

// move viewport by the amount of the resize for negative columns
const change = size - this.headingResizeViewport.originalSize;
this.app.viewport.x = this.headingResizeViewport.viewportStart + change;
this.app.viewport.x = this.headingResizeViewport.viewportStart + change * this.app.viewport.scale.x;
this.headingResizeViewport.change = change;
}

Expand All @@ -184,7 +184,7 @@ export class PointerHeading {

// move viewport by the amount of the resize for negative columns
const change = size - this.headingResizeViewport.originalSize;
this.app.viewport.y = this.headingResizeViewport.viewportStart + change;
this.app.viewport.y = this.headingResizeViewport.viewportStart + change * this.app.viewport.scale.x;
this.headingResizeViewport.change = change;
}

Expand Down

0 comments on commit 4f612dc

Please sign in to comment.