Skip to content

Commit

Permalink
feat: autocomplete borders (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfig committed May 30, 2023
1 parent 17beade commit a42df6d
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 69 deletions.
7 changes: 5 additions & 2 deletions src/grid/controller/runners/setBorderRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ export const SetBorderRunner = (sheet: Sheet, statement: Statement, app?: PixiAp
reverse_statement.data.border = sheet.borders.get(statement.data.position[0], statement.data.position[1]);

// set border
if (border === undefined) sheet.borders.clear([{ x: statement.data.position[0], y: statement.data.position[1] }]);
else sheet.borders.update([border]);
if (border === undefined || (!border.horizontal && !border.vertical)) {
sheet.borders.clear([{ x: statement.data.position[0], y: statement.data.position[1] }]);
} else {
sheet.borders.update([border]);
}

// return reverse statement
return reverse_statement;
Expand Down
19 changes: 17 additions & 2 deletions src/grid/sheet/CellRectangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,26 @@ export class CellRectangle {
this.cells = cells;
}

addBorders(gridBorders: GridBorders): void {
this.borders = gridBorders.getBorders(this.size);
/**
* adds a simple list of borders in the CellRectangle's cells (does not create a full array like cells for now)
* @param gridBorders
* @param extend - extends borders one to the right and one down (to cover "neighboring" border)
*/
addBorders(gridBorders: GridBorders, extend?: boolean): void {
if (extend) {
this.borders = gridBorders.getBorders(
new Rectangle(this.size.left, this.size.top, this.size.width + 1, this.size.height + 1)
);
} else {
this.borders = gridBorders.getBorders(this.size);
}
}

get(x: number, y: number): CellAndFormat | undefined {
return this.cells[y * (this.size.width + 1) + x];
}

getBorder(x: number, y: number): Border | undefined {
return this.borders?.find((border) => border.x === x && border.y === y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export class PointerAutoComplete {
if (!setInteractionState) throw new Error('Expected setInteractionState to be defined in PointerAutoComplete');

// handle dragging from the corner
if (intersects.rectanglePoint(this.app.cursor.indicator, world)) {
} else if (this.active) {
// if (intersects.rectanglePoint(this.app.cursor.indicator, world)) {
if (this.active) {
const { column, row } = this.app.sheet.gridOffsets.getRowColumnFromWorld(world.x, world.y);
const { selection, screenSelection } = this;
if (!selection || !screenSelection) {
Expand Down Expand Up @@ -135,6 +135,7 @@ export class PointerAutoComplete {
rectangle.height = row - selection.y + 1;
} else {
this.stateVertical = undefined;
this.toVertical = undefined;
}

if (column === selection.left && selection.left === selection.right) {
Expand Down Expand Up @@ -164,6 +165,7 @@ export class PointerAutoComplete {
rectangle.width = column - selection.x + 1;
} else {
this.stateHorizontal = undefined;
this.toHorizontal = undefined;
}
this.app.boxCells.populate({
gridRectangle: rectangle,
Expand Down
Loading

1 comment on commit a42df6d

@vercel
Copy link

@vercel vercel bot commented on a42df6d May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

quadratic – ./

quadratic-nu.vercel.app
quadratic-quadratic.vercel.app
quadratic-git-main-quadratic.vercel.app

Please sign in to comment.