Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jump to axis on Cmd + (Shift)? + Arrow keys #1627

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,48 @@ async function jumpCursor(deltaX: number, deltaY: number, select: boolean) {
// always use the original cursor position to search
const yCheck = cursor.cursorPosition.y;
// handle case of cell with content
let nextCol: number | undefined = undefined;
if (await quadraticCore.cellHasContent(sheetId, x, yCheck)) {
// if next cell is empty, find the next cell with content
if (!(await quadraticCore.cellHasContent(sheetId, x + 1, yCheck))) {
x = await quadraticCore.findNextColumn({
nextCol = await quadraticCore.findNextColumn({
sheetId,
columnStart: x + 1,
columnStart: x + 2,
row: yCheck,
reverse: false,
withContent: true,
});
}
// if next cell is not empty, find the next empty cell
else {
x =
(await quadraticCore.findNextColumn({
nextCol =
((await quadraticCore.findNextColumn({
sheetId,
columnStart: x + 1,
columnStart: x + 2,
row: yCheck,
reverse: false,
withContent: false,
})) - 1;
})) ?? x + 2) - 1;
}
}
// otherwise find the next cell with content
else {
x = await quadraticCore.findNextColumn({
nextCol = await quadraticCore.findNextColumn({
sheetId,
columnStart: x + 1,
row: yCheck,
reverse: false,
withContent: true,
});
if (x === keyboardX) x++;
}
if (nextCol === undefined) {
nextCol = x < 0 ? 0 : x + 1;
}
x = nextCol;
if (keyboardX < -1) {
x = Math.min(x, -1);
}
if (x === keyboardX) x++;
if (select) {
lastMultiCursor.x = Math.min(cursor.cursorPosition.x, x);
lastMultiCursor.width = Math.abs(cursor.cursorPosition.x - x) + 1;
Expand All @@ -96,47 +104,51 @@ async function jumpCursor(deltaX: number, deltaY: number, select: boolean) {
} else if (deltaX === -1) {
let x = keyboardX;
const y = cursor.keyboardMovePosition.y;

// always use the original cursor position to search
const yCheck = cursor.cursorPosition.y;

// handle case of cell with content
let nextCol: number | undefined = undefined;
if (await quadraticCore.cellHasContent(sheetId, x, yCheck)) {
// if next cell is empty, find the next cell with content
if (!(await quadraticCore.cellHasContent(sheetId, x - 1, yCheck))) {
x = await quadraticCore.findNextColumn({
nextCol = await quadraticCore.findNextColumn({
sheetId,
columnStart: x - 1,
columnStart: x - 2,
row: yCheck,
reverse: true,
withContent: true,
});
}

// if next cell is not empty, find the next empty cell
else {
x =
(await quadraticCore.findNextColumn({
nextCol =
((await quadraticCore.findNextColumn({
sheetId,
columnStart: x - 1,
columnStart: x - 2,
row: yCheck,
reverse: true,
withContent: false,
})) + 1;
})) ?? x - 2) + 1;
}
}

// otherwise find the next cell with content
else {
x = await quadraticCore.findNextColumn({
nextCol = await quadraticCore.findNextColumn({
sheetId,
columnStart: x - 1,
row: yCheck,
reverse: true,
withContent: true,
});
if (x === keyboardX) x--;
}
if (nextCol === undefined) {
nextCol = x > 0 ? 0 : x - 1;
}
x = nextCol;
if (keyboardX > 0) {
x = Math.max(x, 0);
}
if (x === keyboardX) x--;
if (select) {
lastMultiCursor.x = Math.min(cursor.cursorPosition.x, x);
lastMultiCursor.width = Math.abs(cursor.cursorPosition.x - x) + 1;
Expand All @@ -154,40 +166,48 @@ async function jumpCursor(deltaX: number, deltaY: number, select: boolean) {
// always use the original cursor position to search
const xCheck = cursor.cursorPosition.x;
// handle case of cell with content
let nextRow: number | undefined = undefined;
if (await quadraticCore.cellHasContent(sheetId, xCheck, y)) {
// if next cell is empty, find the next cell with content
if (!(await quadraticCore.cellHasContent(sheetId, xCheck, y + 1))) {
y = await quadraticCore.findNextRow({
nextRow = await quadraticCore.findNextRow({
sheetId,
column: xCheck,
rowStart: y + 1,
rowStart: y + 2,
reverse: false,
withContent: true,
});
}
// if next cell is not empty, find the next empty cell
else {
y =
(await quadraticCore.findNextRow({
nextRow =
((await quadraticCore.findNextRow({
sheetId,
column: xCheck,
rowStart: y + 1,
rowStart: y + 2,
reverse: false,
withContent: false,
})) - 1;
})) ?? y + 2) - 1;
}
}
// otherwise find the next cell with content
else {
y = await quadraticCore.findNextRow({
nextRow = await quadraticCore.findNextRow({
sheetId,
column: xCheck,
rowStart: y + 1,
reverse: false,
withContent: true,
});
if (y === keyboardY) y++;
}
if (nextRow === undefined) {
nextRow = y < 0 ? 0 : y + 1;
}
y = nextRow;
if (keyboardY < -1) {
y = Math.min(y, -1);
}
if (y === keyboardY) y++;
if (select) {
lastMultiCursor.y = Math.min(cursor.cursorPosition.y, y);
lastMultiCursor.height = Math.abs(cursor.cursorPosition.y - y) + 1;
Expand All @@ -202,45 +222,51 @@ async function jumpCursor(deltaX: number, deltaY: number, select: boolean) {
} else if (deltaY === -1) {
let y = keyboardY;
const x = cursor.keyboardMovePosition.x;

// always use the original cursor position to search
const xCheck = cursor.cursorPosition.x;

// handle case of cell with content
let nextRow: number | undefined = undefined;
if (await quadraticCore.cellHasContent(sheetId, xCheck, y)) {
// if next cell is empty, find the next cell with content
if (!(await quadraticCore.cellHasContent(sheetId, xCheck, y - 1))) {
y = await quadraticCore.findNextRow({
nextRow = await quadraticCore.findNextRow({
sheetId,
column: xCheck,
rowStart: y - 1,
rowStart: y - 2,
reverse: true,
withContent: true,
});
}
// if next cell is not empty, find the next empty cell
else {
y =
(await quadraticCore.findNextRow({
nextRow =
((await quadraticCore.findNextRow({
sheetId,
column: xCheck,
rowStart: y - 1,
rowStart: y - 2,
reverse: true,
withContent: false,
})) + 1;
})) ?? y - 2) + 1;
}
}
// otherwise find the next cell with content
else {
y = await quadraticCore.findNextRow({
nextRow = await quadraticCore.findNextRow({
sheetId,
column: xCheck,
rowStart: y - 1,
reverse: true,
withContent: true,
});
if (y === keyboardY) y--;
}
if (nextRow === undefined) {
nextRow = y > 0 ? 0 : y - 1;
}
y = nextRow;
if (keyboardY > 0) {
y = Math.max(y, 0);
}
if (y === keyboardY) y--;
if (select) {
lastMultiCursor.y = Math.min(cursor.cursorPosition.y, y);
lastMultiCursor.height = Math.abs(cursor.cursorPosition.y - y) + 1;
Expand Down Expand Up @@ -414,6 +440,7 @@ export function keyboardPosition(event: KeyboardEvent): boolean {
withContent: true,
})
.then((x) => {
x = x ?? bounds.right;
setCursorPosition(x, y);
});
}
Expand All @@ -435,6 +462,7 @@ export function keyboardPosition(event: KeyboardEvent): boolean {
withContent: true,
})
.then((x) => {
x = x ?? bounds.left;
quadraticCore.cellHasContent(sheet.id, x, y).then((hasContent) => {
if (hasContent) {
setCursorPosition(x, y);
Expand All @@ -460,6 +488,7 @@ export function keyboardPosition(event: KeyboardEvent): boolean {
withContent: true,
})
.then((x) => {
x = x ?? bounds.right;
quadraticCore.cellHasContent(sheet.id, x, y).then((hasContent) => {
if (hasContent) {
setCursorPosition(x, y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ export interface ClientCoreFindNextColumn {
export interface CoreClientFindNextColumn {
type: 'coreClientFindNextColumn';
id: number;
column: number;
column?: number;
}

export interface ClientCoreFindNextRow {
Expand All @@ -726,7 +726,7 @@ export interface ClientCoreFindNextRow {
export interface CoreClientFindNextRow {
type: 'coreClientFindNextRow';
id: number;
row: number;
row?: number;
}

export interface ClientCoreCommitTransientResize {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,11 @@ class QuadraticCore {
row: number;
reverse: boolean;
withContent: boolean;
}): Promise<number> {
}): Promise<number | undefined> {
const { sheetId, columnStart, row, reverse, withContent } = options;
return new Promise((resolve) => {
const id = this.id++;
this.waitingForResponse[id] = (message: { column: number }) => {
this.waitingForResponse[id] = (message: { column: number | number }) => {
resolve(message.column);
};
this.send({
Expand All @@ -884,11 +884,11 @@ class QuadraticCore {
rowStart: number;
reverse: boolean;
withContent: boolean;
}): Promise<number> {
}): Promise<number | undefined> {
const { sheetId, column, rowStart, reverse, withContent } = options;
return new Promise((resolve) => {
const id = this.id++;
this.waitingForResponse[id] = (message: { row: number }) => {
this.waitingForResponse[id] = (message: { row: number | undefined }) => {
resolve(message.row);
};
this.send({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ class Core {
});
}

findNextColumn(data: ClientCoreFindNextColumn): Promise<number> {
findNextColumn(data: ClientCoreFindNextColumn): Promise<number | undefined> {
return new Promise((resolve) => {
this.clientQueue.push(() => {
if (!this.gridController) throw new Error('Expected gridController to be defined');
Expand All @@ -753,7 +753,7 @@ class Core {
});
}

findNextRow(data: ClientCoreFindNextRow): Promise<number> {
findNextRow(data: ClientCoreFindNextRow): Promise<number | undefined> {
return new Promise((resolve) => {
this.clientQueue.push(() => {
if (!this.gridController) throw new Error('Expected gridController to be defined');
Expand Down
Loading
Loading