Skip to content

Commit 1e21d3a

Browse files
authored
Merge pull request #1376 from quadratichq/python-cell-ref-render
fix bug with python cell references and sheet id
2 parents 593e9c0 + 112948c commit 1e21d3a

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,17 @@ class InlineEditorHandler {
161161
y: sheet.cursor.originPosition.y,
162162
};
163163
let value: string;
164+
let changeToFormula = false;
164165
if (initialValue) {
165166
value = initialValue;
166167
this.changeToFormula(value[0] === '=');
167168
} else {
168169
const formula = await quadraticCore.getCodeCell(this.location.sheetId, this.location.x, this.location.y);
169170
if (formula?.language === 'Formula') {
170171
value = '=' + formula.code_string;
171-
this.changeToFormula(true);
172+
changeToFormula = true;
172173
} else {
173174
value = (await quadraticCore.getEditCell(this.location.sheetId, this.location.x, this.location.y)) || '';
174-
this.changeToFormula(false);
175175
}
176176
}
177177
inlineEditorMonaco.set(value);
@@ -197,6 +197,7 @@ class InlineEditorHandler {
197197
this.formulaExpandButton.style.lineHeight = this.height + 'px';
198198
inlineEditorMonaco.setColumn(value.length + 1);
199199
this.showDiv();
200+
this.changeToFormula(changeToFormula);
200201
this.updateMonacoCursorPosition();
201202
this.keepCursorVisible();
202203
inlineEditorMonaco.focus();
@@ -447,7 +448,7 @@ class InlineEditorHandler {
447448
this.div.style.pointerEvents = 'none';
448449

449450
if (this.formulaExpandButton) {
450-
this.formulaExpandButton.style.display = 'none';
451+
this.formulaExpandButton.style.visibility = 'hidden';
451452
}
452453
this.showing = false;
453454
}

quadratic-client/src/app/gridGL/UI/cellHighlights/CellHighlights.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { CellPosition, ParseFormulaReturnType, Span } from '../../../helpers/for
1010
import { DASHED } from '../../dashedTextures';
1111
import { drawDashedRectangle, drawDashedRectangleMarching } from './cellHighlightsDraw';
1212

13+
// TODO: these files need to be cleaned up and properly typed. Lots of untyped
14+
// data passed around within the data.
15+
1316
export interface HighlightedCellRange {
1417
column: number;
1518
row: number;
@@ -134,7 +137,13 @@ export class CellHighlights extends Container {
134137
}
135138

136139
private getSheet(cellSheet: string | undefined, sheetId: string): string {
137-
return (cellSheet ? sheets.getSheetByName(cellSheet)?.id : sheetId) ?? sheetId;
140+
if (!cellSheet) return sheetId;
141+
142+
// It may come in as either a sheet id or a sheet name.
143+
if (sheets.getById(cellSheet)) {
144+
return cellSheet;
145+
}
146+
return sheets.getSheetByName(cellSheet)?.id ?? sheetId;
138147
}
139148

140149
public evalCoord(cell: { type: 'Relative' | 'Absolute'; coord: number }, origin: number) {
@@ -145,7 +154,7 @@ export class CellHighlights extends Container {
145154
}
146155

147156
private fromCellRange(
148-
cellRange: { type: 'CellRange'; start: CellPosition; end: CellPosition },
157+
cellRange: { type: 'CellRange'; start: CellPosition; end: CellPosition; sheet?: string },
149158
origin: Coordinate,
150159
sheet: string,
151160
span: Span,
@@ -155,13 +164,12 @@ export class CellHighlights extends Container {
155164
const startY = this.evalCoord(cellRange.start.y, origin.y);
156165
const endX = this.evalCoord(cellRange.end.x, origin.x);
157166
const endY = this.evalCoord(cellRange.end.y, origin.y);
158-
159167
this.highlightedCells.push({
160168
column: startX,
161169
row: startY,
162170
width: endX - startX,
163171
height: endY - startY,
164-
sheet: this.getSheet(cellRange.start.sheet, sheet),
172+
sheet: this.getSheet(cellRange.sheet ?? cellRange.start.sheet, sheet),
165173
span,
166174
index,
167175
});

quadratic-client/src/app/gridGL/pixiApp/urlParams/UrlParamsDev.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class UrlParamsDev {
3737
this.loadSheets();
3838
this.loadCode();
3939
} catch (e) {
40-
console.warn('Unable to parse URL param ?state=');
40+
console.warn('Unable to parse URL param ?state=', e);
4141
}
4242
}
4343
this.setupListeners();

quadratic-client/src/app/helpers/formulaNotation.ts

+3
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ export type CellRef =
2828
type: 'CellRange';
2929
start: CellPosition;
3030
end: CellPosition;
31+
sheet?: string;
3132
}
3233
| {
3334
type: 'Cell';
3435
pos: CellPosition;
36+
sheet?: string;
3537
};
3638

3739
export type ParseFormulaReturnType = {
3840
parse_error_msg: string | undefined;
3941
parse_error_span: { start: number | null; end: number | null } | undefined;
4042
cell_refs: {
43+
sheet?: string;
4144
cell_ref: CellRef;
4245
span: Span;
4346
}[];

quadratic-client/src/app/helpers/parseEditorPythonCell.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SheetRect } from '@/app/quadratic-core-types';
22
import { ParseFormulaReturnType } from './formulaNotation';
33

4-
export function parsePython(cellsAccessed?: SheetRect[] | null) {
4+
export function parsePython(cellsAccessed?: SheetRect[] | null): ParseFormulaReturnType {
55
let parsedEditorContent: ParseFormulaReturnType = {
66
// could be improved to check for errors within the editor content
77
parse_error_msg: undefined,
@@ -21,10 +21,10 @@ export function parsePython(cellsAccessed?: SheetRect[] | null) {
2121
x: { type: 'Absolute', coord: Number(sheetRect.max.x) },
2222
y: { type: 'Absolute', coord: Number(sheetRect.max.y) },
2323
},
24+
sheet: sheetRect.sheet_id.id,
2425
},
2526
span: { start: 0, end: 0 },
2627
});
2728
});
28-
2929
return parsedEditorContent;
3030
}

quadratic-client/src/app/ui/menus/CodeEditor/useEditorCellHighlights.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const useEditorCellHighlights = (
9393
let parsed;
9494

9595
if (language === 'Python') {
96-
parsed = parsePython(cellsAccessed) as ParseFormulaReturnType;
96+
parsed = parsePython(cellsAccessed);
9797
}
9898

9999
if (language === 'Formula') {

quadratic-kernels/python-wasm/poetry.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)