Skip to content

Commit 8f4eaf3

Browse files
Merge pull request #3196 from quadratichq/ayush/fix_edit_cell
fix: inline edit cell
2 parents 2bc70d5 + efc0268 commit 8f4eaf3

File tree

17 files changed

+49
-107
lines changed

17 files changed

+49
-107
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ edition = "2024"
1414
description = "Infinite data grid with Python, JavaScript, and SQL built-in"
1515
repository = "https://github.com/quadratichq/quadratic"
1616
license-file = "LICENSE"
17-
version = "0.13.2"
17+
version = "0.13.3"
1818

1919
[profile.release]
2020
# Tell `rustc` to optimize for small code size.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.13.2
1+
0.13.3

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quadratic",
3-
"version": "0.13.2",
3+
"version": "0.13.3",
44
"author": {
55
"name": "David Kircos",
66
"email": "david@quadratichq.com",

quadratic-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quadratic-api",
3-
"version": "0.13.2",
3+
"version": "0.13.3",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

quadratic-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quadratic-client",
3-
"version": "0.13.2",
3+
"version": "0.13.3",
44
"author": {
55
"name": "David Kircos",
66
"email": "david@quadratichq.com",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "0.13.2"
2+
"version": "0.13.3"
33
}

quadratic-client/src/app/actions/editActionsSpec.ts

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { sheets } from '@/app/grid/controller/Sheets';
1212
import { inlineEditorHandler } from '@/app/gridGL/HTMLGrid/inlineEditor/inlineEditorHandler';
1313
import { CursorMode } from '@/app/gridGL/HTMLGrid/inlineEditor/inlineEditorKeyboard';
1414
import { doubleClickCell } from '@/app/gridGL/interaction/pointer/doubleClickCell';
15-
import { pixiApp } from '@/app/gridGL/pixiApp/PixiApp';
1615
import { pixiAppSettings } from '@/app/gridGL/pixiApp/PixiAppSettings';
1716
import { downloadFile } from '@/app/helpers/downloadFileInBrowser';
1817
import { quadraticCore } from '@/app/web-workers/quadraticCore/quadraticCore';
@@ -187,25 +186,7 @@ export const editActionsSpec: EditActionSpec = {
187186
run: () => {
188187
if (!inlineEditorHandler.isEditingFormula()) {
189188
const cursor = sheets.sheet.cursor.position;
190-
const codeCell = pixiApp.cellsSheet().tables.getCodeCellIntersects(cursor);
191-
if (codeCell) {
192-
doubleClickCell({
193-
column: cursor.x,
194-
row: cursor.y,
195-
cell: '',
196-
cursorMode: CursorMode.Edit,
197-
});
198-
} else {
199-
quadraticCore.getEditCell(sheets.current, cursor.x, cursor.y).then((cell) => {
200-
doubleClickCell({
201-
column: cursor.x,
202-
row: cursor.y,
203-
cell,
204-
cursorMode: cell ? CursorMode.Edit : CursorMode.Enter,
205-
});
206-
});
207-
}
208-
189+
doubleClickCell({ column: cursor.x, row: cursor.y, cursorMode: CursorMode.Edit });
209190
return true;
210191
}
211192
},
@@ -215,19 +196,7 @@ export const editActionsSpec: EditActionSpec = {
215196
run: () => {
216197
if (!inlineEditorHandler.isEditingFormula()) {
217198
const cursor = sheets.sheet.cursor.position;
218-
const codeCell = pixiApp.cellsSheet().tables.getCodeCellIntersects(cursor);
219-
if (codeCell) {
220-
doubleClickCell({
221-
column: codeCell.x,
222-
row: codeCell.y,
223-
cell: '',
224-
cursorMode: CursorMode.Edit,
225-
});
226-
} else {
227-
quadraticCore.getEditCell(sheets.current, cursor.x, cursor.y).then((cell) => {
228-
doubleClickCell({ column: cursor.x, row: cursor.y, cell, cursorMode: CursorMode.Edit });
229-
});
230-
}
199+
doubleClickCell({ column: cursor.x, row: cursor.y, cell: '', cursorMode: CursorMode.Edit });
231200
return true;
232201
}
233202
},

quadratic-client/src/app/gridGL/HTMLGrid/inlineEditor/inlineEditorHandler.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ class InlineEditorHandler {
175175

176176
// Handler for the changeInput event.
177177
private changeInput = async (input: boolean, initialValue?: string, cursorMode?: CursorMode) => {
178-
if (!input && !this.open) return;
178+
if (!input && !this.open) {
179+
return;
180+
}
179181

180182
if (initialValue) {
181183
this.initialValue += initialValue;
@@ -185,8 +187,9 @@ class InlineEditorHandler {
185187
}
186188

187189
if (!this.div) {
188-
throw new Error('Expected div and editor to be defined in InlineEditorHandler');
190+
return;
189191
}
192+
190193
if (input) {
191194
const sheet = sheets.sheet;
192195
const cursor = sheet.cursor.position;
@@ -195,23 +198,42 @@ class InlineEditorHandler {
195198
x: cursor.x,
196199
y: cursor.y,
197200
};
198-
this.codeCell = pixiApp.cellsSheet().tables.getCodeCellIntersects(this.location);
201+
199202
let value: string;
200203
let changeToFormula = false;
204+
201205
if (initialValue) {
206+
changeToFormula = initialValue[0] === '=';
207+
202208
value = initialValue;
203-
changeToFormula = value[0] === '=';
204209
} else {
205210
const formula = await quadraticCore.getCodeCell(this.location.sheetId, this.location.x, this.location.y);
211+
206212
if (formula?.language === 'Formula') {
207-
value = '=' + formula.code_string;
208213
changeToFormula = true;
214+
215+
value = '=' + formula.code_string;
209216
} else {
210-
value = (await quadraticCore.getEditCell(this.location.sheetId, this.location.x, this.location.y)) || '';
211217
changeToFormula = false;
218+
219+
const jsCellValue = await quadraticCore.getCellValue(this.location.sheetId, this.location.x, this.location.y);
220+
if (jsCellValue) {
221+
value = jsCellValue.kind === 'number' ? parseFloat(jsCellValue.value).toString() : jsCellValue.value;
222+
223+
// open the calendar pick if the cell is a date
224+
if (['date', 'date time'].includes(jsCellValue.kind)) {
225+
pixiAppSettings.setEditorInteractionState?.({
226+
...pixiAppSettings.editorInteractionState,
227+
annotationState: `calendar${jsCellValue.kind === 'date time' ? '-time' : ''}`,
228+
});
229+
}
230+
} else {
231+
value = '';
232+
}
212233
}
213234
}
214235

236+
this.codeCell = pixiApp.cellsSheet().tables.getCodeCellIntersects(this.location);
215237
if (this.codeCell?.language === 'Import' && changeToFormula) {
216238
pixiAppSettings.snackbar('Cannot create formula inside table', { severity: 'error' });
217239
this.closeIfOpen();
@@ -225,6 +247,7 @@ class InlineEditorHandler {
225247
cursorMode = value ? CursorMode.Edit : CursorMode.Enter;
226248
}
227249
}
250+
228251
pixiAppSettings.setInlineEditorState?.((prev) => ({
229252
...prev,
230253
editMode: cursorMode === CursorMode.Edit,
@@ -249,6 +272,7 @@ class InlineEditorHandler {
249272
this.showDiv();
250273
this.changeToFormula(changeToFormula);
251274
this.updateMonacoCursorPosition();
275+
252276
inlineEditorEvents.emit('status', true, value);
253277

254278
// this needs to be at the end to avoid a race condition where the cursor

quadratic-client/src/app/gridGL/interaction/keyboard/keyboardCell.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,7 @@ export function keyboardCell(event: React.KeyboardEvent<HTMLElement>): boolean {
8080
if (matchShortcut(Action.EditCell, event)) {
8181
if (!inlineEditorHandler.isEditingFormula()) {
8282
const pos = sheets.sheet.cursor.position;
83-
const { x, y } = pos;
84-
const codeCell = pixiApp.cellsSheet().tables.getCodeCellIntersects(pos);
85-
if (codeCell) {
86-
doubleClickCell({
87-
column: x,
88-
row: y,
89-
});
90-
} else {
91-
quadraticCore.getEditCell(sheets.current, x, y).then((cell) => {
92-
doubleClickCell({
93-
column: x,
94-
row: y,
95-
cell,
96-
cursorMode: cell ? CursorMode.Edit : CursorMode.Enter,
97-
});
98-
});
99-
}
83+
doubleClickCell({ column: pos.x, row: pos.y });
10084
return true;
10185
}
10286
}
@@ -105,19 +89,7 @@ export function keyboardCell(event: React.KeyboardEvent<HTMLElement>): boolean {
10589
if (matchShortcut(Action.ToggleArrowMode, event)) {
10690
if (!inlineEditorHandler.isEditingFormula()) {
10791
const pos = sheets.sheet.cursor.position;
108-
const { x, y } = pos;
109-
const codeCell = pixiApp.cellsSheet().tables.getCodeCellIntersects(pos);
110-
if (codeCell) {
111-
doubleClickCell({
112-
column: x,
113-
row: y,
114-
cursorMode: CursorMode.Edit,
115-
});
116-
} else {
117-
quadraticCore.getEditCell(sheets.current, x, y).then((cell) => {
118-
doubleClickCell({ column: x, row: y, cell, cursorMode: CursorMode.Edit });
119-
});
120-
}
92+
doubleClickCell({ column: pos.x, row: pos.y, cursorMode: CursorMode.Edit });
12193
return true;
12294
}
12395
}

quadratic-client/src/app/gridGL/interaction/pointer/PointerDown.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { PanMode } from '@/app/atoms/gridPanModeAtom';
33
import { events } from '@/app/events/events';
44
import { sheets } from '@/app/grid/controller/Sheets';
55
import { inlineEditorHandler } from '@/app/gridGL/HTMLGrid/inlineEditor/inlineEditorHandler';
6-
import { CursorMode } from '@/app/gridGL/HTMLGrid/inlineEditor/inlineEditorKeyboard';
76
import { inlineEditorMonaco } from '@/app/gridGL/HTMLGrid/inlineEditor/inlineEditorMonaco';
87
import { doubleClickCell } from '@/app/gridGL/interaction/pointer/doubleClickCell';
98
import { DOUBLE_CLICK_TIME } from '@/app/gridGL/interaction/pointer/pointerUtils';
109
import { pixiApp } from '@/app/gridGL/pixiApp/PixiApp';
1110
import { pixiAppSettings } from '@/app/gridGL/pixiApp/PixiAppSettings';
12-
import { quadraticCore } from '@/app/web-workers/quadraticCore/quadraticCore';
1311
import { isLinux } from '@/shared/utils/isLinux';
1412
import { isMac } from '@/shared/utils/isMac';
1513
import { Point, Rectangle, type FederatedPointerEvent } from 'pixi.js';
@@ -113,13 +111,7 @@ export class PointerDown {
113111
return;
114112
}
115113
event.preventDefault();
116-
const codeCell = pixiApp.cellsSheet().tables.getCodeCellIntersects({ x: column, y: row });
117-
if (codeCell) {
118-
doubleClickCell({ column, row });
119-
} else {
120-
const cell = await quadraticCore.getEditCell(sheets.current, column, row);
121-
doubleClickCell({ column, row, cell, cursorMode: cell ? CursorMode.Edit : CursorMode.Enter });
122-
}
114+
doubleClickCell({ column, row });
123115
this.active = false;
124116
return;
125117
}

0 commit comments

Comments
 (0)