Skip to content

Commit 2d5903b

Browse files
adjust_code_cell_references, remove rc in formulas
1 parent c01b08e commit 2d5903b

File tree

51 files changed

+399
-839
lines changed

Some content is hidden

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

51 files changed

+399
-839
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 & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,10 @@ impl A1Selection {
88
///
99
/// Returns an error if ranges refer to different sheets. Ranges without an
1010
/// 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-
19-
/// Parses a selection from a comma-separated list of ranges.
20-
///
21-
/// Returns an error if ranges refer to different sheets. Ranges without an
22-
/// explicit sheet use `default_sheet_id`.
23-
///
24-
/// If `base_pos` is `None`, then only A1 notation is accepted. If it is
25-
/// `Some`, then A1 and RC notation are both accepted.
2611
pub fn parse(
2712
s: &str,
2813
default_sheet_id: SheetId,
2914
a1_context: &A1Context,
30-
base_pos: Option<Pos>,
3115
) -> Result<Self, A1Error> {
3216
let mut sheet = None;
3317
let mut ranges = vec![];
@@ -77,8 +61,7 @@ impl A1Selection {
7761

7862
let mut sheet_id = None;
7963
for segment in segments {
80-
let range =
81-
SheetCellRefRange::parse(segment.trim(), default_sheet_id, a1_context, base_pos)?;
64+
let range = SheetCellRefRange::parse(segment.trim(), default_sheet_id, a1_context)?;
8265
if *sheet.get_or_insert(range.sheet_id) != range.sheet_id {
8366
return Err(A1Error::TooManySheets(s.to_string()));
8467
}
@@ -110,7 +93,7 @@ mod tests {
11093
let sheet_id = SheetId::TEST;
11194
let context = A1Context::default();
11295
assert_eq!(
113-
A1Selection::parse_a1("A1", sheet_id, &context),
96+
A1Selection::parse("A1", sheet_id, &context),
11497
Ok(A1Selection::from_xy(1, 1, sheet_id)),
11598
);
11699
}
@@ -120,7 +103,7 @@ mod tests {
120103
let sheet_id = SheetId::TEST;
121104
let context = A1Context::default();
122105
assert_eq!(
123-
A1Selection::parse_a1("*", sheet_id, &context),
106+
A1Selection::parse("*", sheet_id, &context),
124107
Ok(A1Selection::from_range(
125108
CellRefRange::ALL,
126109
sheet_id,
@@ -134,15 +117,15 @@ mod tests {
134117
let sheet_id = SheetId::TEST;
135118
let context = A1Context::default();
136119
assert_eq!(
137-
A1Selection::parse_a1("A1:B2", sheet_id, &context),
120+
A1Selection::parse("A1:B2", sheet_id, &context),
138121
Ok(A1Selection::test_a1("A1:B2")),
139122
);
140123
assert_eq!(
141-
A1Selection::parse_a1("D1:A5", sheet_id, &context),
124+
A1Selection::parse("D1:A5", sheet_id, &context),
142125
Ok(A1Selection::test_a1("D1:A5")),
143126
);
144127
assert_eq!(
145-
A1Selection::parse_a1("A1:B2,D1:A5", sheet_id, &context),
128+
A1Selection::parse("A1:B2,D1:A5", sheet_id, &context),
146129
Ok(A1Selection::test_a1("A1:B2,D1:A5")),
147130
);
148131
}
@@ -152,7 +135,7 @@ mod tests {
152135
let sheet_id = SheetId::TEST;
153136
let context = A1Context::default();
154137
let selection =
155-
A1Selection::parse_a1("A1,B1:D2,E:G,2:3,5:7,F6:G8,4", sheet_id, &context).unwrap();
138+
A1Selection::parse("A1,B1:D2,E:G,2:3,5:7,F6:G8,4", sheet_id, &context).unwrap();
156139

157140
assert_eq!(selection.sheet_id, sheet_id);
158141
assert_eq!(selection.cursor, pos![A4]);
@@ -175,7 +158,7 @@ mod tests {
175158
let sheet_id = SheetId::TEST;
176159
let context = A1Context::default();
177160
assert_eq!(
178-
A1Selection::parse_a1("1", sheet_id, &context),
161+
A1Selection::parse("1", sheet_id, &context),
179162
Ok(A1Selection::from_range(
180163
CellRefRange::new_relative_row(1),
181164
sheet_id,
@@ -184,12 +167,12 @@ mod tests {
184167
);
185168

186169
assert_eq!(
187-
A1Selection::parse_a1("1:3", sheet_id, &context),
170+
A1Selection::parse("1:3", sheet_id, &context),
188171
Ok(A1Selection::test_a1("1:3")),
189172
);
190173

191174
assert_eq!(
192-
A1Selection::parse_a1("1:", sheet_id, &context),
175+
A1Selection::parse("1:", sheet_id, &context),
193176
Ok(A1Selection::test_a1("*")),
194177
);
195178
}
@@ -200,7 +183,7 @@ mod tests {
200183
let sheet_id2 = SheetId::new();
201184
let context = A1Context::test(&[("Sheet1", sheet_id), ("Second", sheet_id2)], &[]);
202185
assert_eq!(
203-
A1Selection::parse_a1("'Second'!A1", sheet_id, &context),
186+
A1Selection::parse("'Second'!A1", sheet_id, &context),
204187
Ok(A1Selection::from_xy(1, 1, sheet_id2)),
205188
);
206189
}
@@ -210,7 +193,7 @@ mod tests {
210193
let sheet_id = SheetId::TEST;
211194
let context = A1Context::default();
212195
assert_eq!(
213-
A1Selection::parse_a1("Sheet' 1'!A1", sheet_id, &context),
196+
A1Selection::parse("Sheet' 1'!A1", sheet_id, &context),
214197
Err(A1Error::InvalidSheetName("Sheet' 1'!A1".to_string())),
215198
);
216199
}
@@ -223,7 +206,7 @@ mod tests {
223206
&[("test_table", &["Col1"], Rect::test_a1("A1:C3"))],
224207
);
225208
assert_eq!(
226-
A1Selection::parse_a1(
209+
A1Selection::parse(
227210
"test_table[[#DATA],[#HEADERS],[Col1]],A1",
228211
sheet_id,
229212
&context
@@ -238,7 +221,7 @@ mod tests {
238221
&[("test_table-2.csv", &["Col1"], Rect::test_a1("A1:C3"))],
239222
);
240223
assert_eq!(
241-
A1Selection::parse_a1("test_table-2.csv[Col1]", sheet_id, &context)
224+
A1Selection::parse("test_table-2.csv[Col1]", sheet_id, &context)
242225
.unwrap()
243226
.to_string(Some(sheet_id), &context),
244227
"test_table-2.csv[Col1]".to_string(),

quadratic-core/src/a1/cell_ref_coord.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,6 @@ impl CellRefCoord {
105105
write!(f, "{}", self.coord)
106106
}
107107

108-
/// Returns the number as a string for use in RC-style notation.
109-
///
110-
/// - If the coordinate is relative, returns a string containing the number
111-
/// surrounded by square brackets.
112-
/// - If the coordinate is absolute, returns a string containing the number.
113-
pub(crate) fn to_rc_string(self, base_coord: i64) -> String {
114-
match self.is_absolute {
115-
true => format!("{{{}}}", self.coord),
116-
false => format!("[{}]", self.coord.saturating_sub(base_coord)), // when changing to `u64`, this MUST stay `i64`
117-
}
118-
}
119-
120108
pub fn new_rel(coord: i64) -> Self {
121109
let is_absolute = false;
122110
Self { coord, is_absolute }

0 commit comments

Comments
 (0)