Compare commits

3 Commits

Author SHA1 Message Date
b41a69781c merge cleanup
Some checks failed
Test Rust project / test (ubuntu-latest, stable) (push) Failing after 39s
2026-02-07 20:55:05 -07:00
f654ce37a6 Merge branch 'full-copy-history' 2026-02-07 20:52:14 -07:00
1825460074 add failing test
Some checks failed
Test Rust project / test (ubuntu-latest, stable) (push) Failing after 48s
2026-02-07 19:30:08 -07:00
2 changed files with 50 additions and 17 deletions

View File

@@ -391,10 +391,12 @@ impl Grid {
}); });
} }
pub fn insert_row_below(&mut self, (x, y): (usize, usize)) { pub fn insert_row_below(&mut self, (x, y): (usize, usize)) {
self.insert_row_above((x, y + 1)); self.insert_row_above((x, y + 1));
} }
pub fn insert_column_before(&mut self, (insertion_x, _y): (usize, usize)) { pub fn insert_column_before(&mut self, (insertion_x, _y): (usize, usize)) {
self.transact_on_grid(|grid| { self.transact_on_grid(|grid| {
grid.insert_column(insertion_x); grid.insert_column(insertion_x);
@@ -417,6 +419,7 @@ impl Grid {
}); });
} }
pub fn insert_column_after(&mut self, (x, y): (usize, usize)) { pub fn insert_column_after(&mut self, (x, y): (usize, usize)) {
self.insert_column_before((x + 1, y)); self.insert_column_before((x + 1, y));
} }
@@ -467,6 +470,20 @@ impl Grid {
} }
} }
pub fn range_as_indices(range: &str) -> Option<(usize, usize)> {
let v = range.split(':').collect::<Vec<&str>>();
if v.len() == 2 {
let start_col = v[0];
let end_col = v[1];
let start_idx = Grid::char_to_idx(start_col);
let end_idx = Grid::char_to_idx(end_col);
return Some((start_idx, end_idx))
}
None
}
pub fn char_to_idx(i: &str) -> usize { pub fn char_to_idx(i: &str) -> usize {
let x_idx = i let x_idx = i
.chars() .chars()
@@ -1078,6 +1095,36 @@ fn insert_col_before_3() {
assert_eq!(cell.to_string(), "=B0*B1"); assert_eq!(cell.to_string(), "=B0*B1");
} }
#[test]
fn insert_col_before_static_range() {
let mut grid = Grid::new();
grid.set_cell("A0", 2.);
grid.set_cell("A1", 2.);
grid.set_cell("B0", "=sum(A:A)".to_string());
grid.mv_cursor_to(0, 1);
grid.insert_column_before(grid.cursor());
let cell = grid.get_cell("C0").as_ref().expect("Just set it");
assert_eq!(cell.to_string(), "=sum(A:A)");
}
#[test]
fn insert_col_before_move_range() {
let mut grid = Grid::new();
grid.set_cell("B0", 2.);
grid.set_cell("B1", 2.);
grid.set_cell("A0", "=sum(B:B)".to_string());
grid.mv_cursor_to(0, 0);
grid.insert_column_after(grid.cursor());
let cell = grid.get_cell("A0").as_ref().expect("Just set it");
assert_eq!(cell.to_string(), "=sum(C:C)");
}
#[test] #[test]
fn insert_row_above_1() { fn insert_row_above_1() {
let mut grid = Grid::new(); let mut grid = Grid::new();

View File

@@ -16,26 +16,12 @@ pub struct CallbackContext<'a> {
impl<'a> CallbackContext<'a> { impl<'a> CallbackContext<'a> {
fn expand_range(&self, range: &str) -> Option<Vec<&CellType>> { fn expand_range(&self, range: &str) -> Option<Vec<&CellType>> {
let v = range.split(':').collect::<Vec<&str>>(); if let Some((start, end)) = Grid::range_as_indices(range) {
if v.len() == 2 {
let start_col = v[0];
let end_col = v[1];
let as_index = |s: &str| {
s.char_indices()
// .filter(|f| f.1 as u8 >= 97) // prevent sub with overflow errors
.map(|(idx, c)| ((c.to_ascii_lowercase() as usize).saturating_sub(97)) + (26 * idx))
.fold(0, |a, b| a + b)
};
let start_idx = as_index(start_col);
let end_idx = as_index(end_col);
let mut buf = Vec::new(); let mut buf = Vec::new();
for x in start_idx..=end_idx { for x in start..=end {
for y in 0..=self.variables.get_grid().max_y_at_x(x) { for y in 0..=self.variables.get_grid().max_y_at_x(x) {
if let Some(s) = self.variables.get_grid().get_cell_raw(x, y) { if let Some(s) = self.variables.get_cell_raw(x, y) {
buf.push(s); buf.push(s);
} }
} }