Skip to content

Commit 35303d3

Browse files
adjust_code_cell_references, migrate rc in formulas, v1_12
1 parent c01b08e commit 35303d3

File tree

47 files changed

+728
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+728
-560
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class InlineEditorFormula {
2424
cellHighlights(location: SheetPosTS, formula: string) {
2525
let parseResult: JsFormulaParseResult;
2626
try {
27-
parseResult = parseFormula(formula, sheets.jsA1Context, location.sheetId, location.x, location.y);
27+
parseResult = parseFormula(formula, sheets.jsA1Context, location.sheetId);
2828
} catch (e) {
2929
this.clearDecorations();
3030
return;
@@ -146,13 +146,13 @@ class InlineEditorFormula {
146146
const location = inlineEditorHandler.location;
147147
if (!location) return false;
148148
const formula = (testFormula ?? inlineEditorMonaco.get()).slice(1);
149-
if (!checkFormula(formula, sheets.jsA1Context, location.sheetId, location.x, location.y)) {
149+
if (!checkFormula(formula, sheets.jsA1Context, location.sheetId)) {
150150
if (skipCloseParenthesisCheck) {
151151
return false;
152152
}
153153
const value = this.closeParentheses();
154154
if (value && value !== testFormula) {
155-
return checkFormula(value, sheets.jsA1Context, location.sheetId, location.x, location.y);
155+
return checkFormula(value, sheets.jsA1Context, location.sheetId);
156156
} else {
157157
return false;
158158
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const useEditorCellHighlights = (
7373
} else if (codeCell.language === 'Formula') {
7474
let parsed: JsFormulaParseResult;
7575
try {
76-
parsed = parseFormula(modelValue, sheets.jsA1Context, codeCell.sheetId, codeCell.pos.x, codeCell.pos.y);
76+
parsed = parseFormula(modelValue, sheets.jsA1Context, codeCell.sheetId);
7777
} catch (e) {
7878
console.error(e);
7979
return;

quadratic-core/src/a1/a1_selection/create.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,19 @@ impl A1Selection {
254254
/// Returns a test selection from the A1-string with SheetId::TEST.
255255
#[cfg(test)]
256256
pub fn test_a1(a1: &str) -> Self {
257-
Self::parse(a1, SheetId::TEST, &A1Context::default(), None).unwrap()
257+
Self::parse(a1, SheetId::TEST, &A1Context::default()).unwrap()
258258
}
259259

260260
/// Returns a test selection from the A1-string with the given sheet ID.
261261
#[cfg(test)]
262262
pub fn test_a1_sheet_id(a1: &str, sheet_id: SheetId) -> Self {
263-
Self::parse(a1, sheet_id, &A1Context::default(), None).unwrap()
263+
Self::parse(a1, sheet_id, &A1Context::default()).unwrap()
264264
}
265265

266266
#[cfg(test)]
267267
#[track_caller]
268268
pub fn test_a1_context(a1: &str, a1_context: &A1Context) -> Self {
269-
Self::parse(a1, SheetId::TEST, a1_context, None).unwrap()
269+
Self::parse(a1, SheetId::TEST, a1_context).unwrap()
270270
}
271271
}
272272

quadratic-core/src/a1/a1_selection/display.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ mod tests {
150150
#[test]
151151
fn test_extra_comma() {
152152
let sheet_id = SheetId::TEST;
153-
let selection = A1Selection::parse_a1("1,", sheet_id, &A1Context::default()).unwrap();
153+
let selection = A1Selection::parse("1,", sheet_id, &A1Context::default()).unwrap();
154154
assert_eq!(
155155
selection.to_string(Some(sheet_id), &A1Context::default()),
156156
"1:1",
@@ -160,7 +160,7 @@ mod tests {
160160
#[test]
161161
fn test_multiple_one_sized_rects() {
162162
let sheet_id = SheetId::TEST;
163-
let selection = A1Selection::parse_a1("A1,B1,C1", sheet_id, &A1Context::default()).unwrap();
163+
let selection = A1Selection::parse("A1,B1,C1", sheet_id, &A1Context::default()).unwrap();
164164
assert_eq!(
165165
selection.to_string(Some(sheet_id), &A1Context::default()),
166166
"A1,B1,C1",
@@ -173,7 +173,7 @@ mod tests {
173173
let sheet_second = SheetId::new();
174174
let context = A1Context::test(&[("First", sheet_id), ("Second", sheet_second)], &[]);
175175
let selection =
176-
A1Selection::parse_a1("second!A1,second!B1,second!C1", sheet_id, &context).unwrap();
176+
A1Selection::parse("second!A1,second!B1,second!C1", sheet_id, &context).unwrap();
177177
assert_eq!(
178178
selection.to_string(Some(sheet_id), &context),
179179
"Second!A1,Second!B1,Second!C1",

quadratic-core/src/a1/a1_selection/parse.rs

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ use crate::a1::{A1Context, A1Error, SheetCellRefRange};
33
use super::*;
44

55
impl A1Selection {
6-
/// Parses a selection from a comma-separated list of ranges, using only A1
7-
/// notation (not RC).
8-
///
9-
/// Returns an error if ranges refer to different sheets. Ranges without an
10-
/// explicit sheet use `default_sheet_id`.
11-
pub fn parse_a1(
12-
a1: &str,
13-
default_sheet_id: SheetId,
14-
a1_context: &A1Context,
15-
) -> Result<Self, A1Error> {
16-
Self::parse(a1, default_sheet_id, a1_context, None)
17-
}
18-
196
/// Parses a selection from a comma-separated list of ranges.
207
///
218
/// Returns an error if ranges refer to different sheets. Ranges without an
@@ -27,7 +14,6 @@ impl A1Selection {
2714
s: &str,
2815
default_sheet_id: SheetId,
2916
a1_context: &A1Context,
30-
base_pos: Option<Pos>,
3117
) -> Result<Self, A1Error> {
3218
let mut sheet = None;
3319
let mut ranges = vec![];
@@ -77,8 +63,7 @@ impl A1Selection {
7763

7864
let mut sheet_id = None;
7965
for segment in segments {
80-
let range =
81-
SheetCellRefRange::parse(segment.trim(), default_sheet_id, a1_context, base_pos)?;
66+
let range = SheetCellRefRange::parse_a1(segment.trim(), default_sheet_id, a1_context)?;
8267
if *sheet.get_or_insert(range.sheet_id) != range.sheet_id {
8368
return Err(A1Error::TooManySheets(s.to_string()));
8469
}
@@ -110,7 +95,7 @@ mod tests {
11095
let sheet_id = SheetId::TEST;
11196
let context = A1Context::default();
11297
assert_eq!(
113-
A1Selection::parse_a1("A1", sheet_id, &context),
98+
A1Selection::parse("A1", sheet_id, &context),
11499
Ok(A1Selection::from_xy(1, 1, sheet_id)),
115100
);
116101
}
@@ -120,7 +105,7 @@ mod tests {
120105
let sheet_id = SheetId::TEST;
121106
let context = A1Context::default();
122107
assert_eq!(
123-
A1Selection::parse_a1("*", sheet_id, &context),
108+
A1Selection::parse("*", sheet_id, &context),
124109
Ok(A1Selection::from_range(
125110
CellRefRange::ALL,
126111
sheet_id,
@@ -134,15 +119,15 @@ mod tests {
134119
let sheet_id = SheetId::TEST;
135120
let context = A1Context::default();
136121
assert_eq!(
137-
A1Selection::parse_a1("A1:B2", sheet_id, &context),
122+
A1Selection::parse("A1:B2", sheet_id, &context),
138123
Ok(A1Selection::test_a1("A1:B2")),
139124
);
140125
assert_eq!(
141-
A1Selection::parse_a1("D1:A5", sheet_id, &context),
126+
A1Selection::parse("D1:A5", sheet_id, &context),
142127
Ok(A1Selection::test_a1("D1:A5")),
143128
);
144129
assert_eq!(
145-
A1Selection::parse_a1("A1:B2,D1:A5", sheet_id, &context),
130+
A1Selection::parse("A1:B2,D1:A5", sheet_id, &context),
146131
Ok(A1Selection::test_a1("A1:B2,D1:A5")),
147132
);
148133
}
@@ -152,7 +137,7 @@ mod tests {
152137
let sheet_id = SheetId::TEST;
153138
let context = A1Context::default();
154139
let selection =
155-
A1Selection::parse_a1("A1,B1:D2,E:G,2:3,5:7,F6:G8,4", sheet_id, &context).unwrap();
140+
A1Selection::parse("A1,B1:D2,E:G,2:3,5:7,F6:G8,4", sheet_id, &context).unwrap();
156141

157142
assert_eq!(selection.sheet_id, sheet_id);
158143
assert_eq!(selection.cursor, pos![A4]);
@@ -175,7 +160,7 @@ mod tests {
175160
let sheet_id = SheetId::TEST;
176161
let context = A1Context::default();
177162
assert_eq!(
178-
A1Selection::parse_a1("1", sheet_id, &context),
163+
A1Selection::parse("1", sheet_id, &context),
179164
Ok(A1Selection::from_range(
180165
CellRefRange::new_relative_row(1),
181166
sheet_id,
@@ -184,12 +169,12 @@ mod tests {
184169
);
185170

186171
assert_eq!(
187-
A1Selection::parse_a1("1:3", sheet_id, &context),
172+
A1Selection::parse("1:3", sheet_id, &context),
188173
Ok(A1Selection::test_a1("1:3")),
189174
);
190175

191176
assert_eq!(
192-
A1Selection::parse_a1("1:", sheet_id, &context),
177+
A1Selection::parse("1:", sheet_id, &context),
193178
Ok(A1Selection::test_a1("*")),
194179
);
195180
}
@@ -200,7 +185,7 @@ mod tests {
200185
let sheet_id2 = SheetId::new();
201186
let context = A1Context::test(&[("Sheet1", sheet_id), ("Second", sheet_id2)], &[]);
202187
assert_eq!(
203-
A1Selection::parse_a1("'Second'!A1", sheet_id, &context),
188+
A1Selection::parse("'Second'!A1", sheet_id, &context),
204189
Ok(A1Selection::from_xy(1, 1, sheet_id2)),
205190
);
206191
}
@@ -210,7 +195,7 @@ mod tests {
210195
let sheet_id = SheetId::TEST;
211196
let context = A1Context::default();
212197
assert_eq!(
213-
A1Selection::parse_a1("Sheet' 1'!A1", sheet_id, &context),
198+
A1Selection::parse("Sheet' 1'!A1", sheet_id, &context),
214199
Err(A1Error::InvalidSheetName("Sheet' 1'!A1".to_string())),
215200
);
216201
}
@@ -223,7 +208,7 @@ mod tests {
223208
&[("test_table", &["Col1"], Rect::test_a1("A1:C3"))],
224209
);
225210
assert_eq!(
226-
A1Selection::parse_a1(
211+
A1Selection::parse(
227212
"test_table[[#DATA],[#HEADERS],[Col1]],A1",
228213
sheet_id,
229214
&context
@@ -238,7 +223,7 @@ mod tests {
238223
&[("test_table-2.csv", &["Col1"], Rect::test_a1("A1:C3"))],
239224
);
240225
assert_eq!(
241-
A1Selection::parse_a1("test_table-2.csv[Col1]", sheet_id, &context)
226+
A1Selection::parse("test_table-2.csv[Col1]", sheet_id, &context)
242227
.unwrap()
243228
.to_string(Some(sheet_id), &context),
244229
"test_table-2.csv[Col1]".to_string(),

quadratic-core/src/a1/sheet_cell_ref_range.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use serde::{Deserialize, Serialize};
55

6-
use crate::{Pos, RefAdjust, RefError, SheetPos, grid::SheetId};
6+
use crate::{Pos, RefAdjust, RefError, grid::SheetId};
77

88
use super::{A1Context, A1Error, CellRefRange, parse_optional_sheet_name_to_id};
99

@@ -16,14 +16,6 @@ pub struct SheetCellRefRange {
1616
}
1717

1818
impl SheetCellRefRange {
19-
/// Parses a cell range reference using A1 or RC notation.
20-
///
21-
/// Ranges without an explicit sheet use `pos.sheet_id`.
22-
///
23-
/// This is a wrapper around [`Self::parse()`] that takes a [`SheetPos`].
24-
pub fn parse_at(a1: &str, pos: SheetPos, a1_context: &A1Context) -> Result<Self, A1Error> {
25-
Self::parse(a1, pos.sheet_id, a1_context, Some(pos.into()))
26-
}
2719
/// Parses a cell range reference using A1 notation.
2820
///
2921
/// Ranges without an explicit sheet use `default_sheet_id`.

0 commit comments

Comments
 (0)