Skip to content

Commit

Permalink
Select full table on table move
Browse files Browse the repository at this point in the history
  • Loading branch information
ddimaria committed Feb 7, 2025
1 parent 29696c5 commit 15d0cf3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 79 deletions.
15 changes: 13 additions & 2 deletions quadratic-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ path = "src/bin/upgrade_file.rs"
[features]
default = ["console_error_panic_hook", "js"]
# "js" feature is disabled for testing (particularly WASI benchmarks)
js = ["js-sys", "serde-wasm-bindgen", "ts-rs", "wasm-bindgen", "wasm-bindgen-futures"]
js = [
"js-sys",
"serde-wasm-bindgen",
"ts-rs",
"wasm-bindgen",
"wasm-bindgen-futures",
]
show-operations = []
multiplayer = []
files = []
Expand Down Expand Up @@ -82,7 +88,12 @@ csv = "1.3.0"
indexmap = { version = "2.0.2", features = ["serde"] }
thiserror = "1.0.52"
lazy_static = "1.4.0"
parquet = { version = "51.0.0", default-features = false, features = ["arrow", "arrow-array", "flate2", "snap"] }
parquet = { version = "51.0.0", default-features = false, features = [
"arrow",
"arrow-array",
"flate2",
"snap",
] }
bytes = "1.5.0"
arrow-array = "51.0.0"
arrow-schema = "51.0.0"
Expand Down
2 changes: 0 additions & 2 deletions quadratic-core/src/a1/a1_selection/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ impl A1Selection {
/// reference.
pub(crate) fn check_for_table_ref(&mut self, context: &A1Context) {
if let Some(last) = self.ranges.last_mut() {
dbgjs!(format!("last: {:?}", last));
if let Some(table_ref) = last.check_for_table_ref(self.sheet_id, context) {
dbgjs!(format!("table_ref: {:?}", table_ref));
*last = table_ref;
}
}
Expand Down
92 changes: 18 additions & 74 deletions quadratic-core/src/a1/cell_ref_range/to_table_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,18 @@ impl CellRefRange {
y: range.end.row().max(range.start.row()),
};

dbgjs!(format!("start: {:?}", start));
dbgjs!(format!("end: {:?}", end));

if let Some(table) = context.table_from_pos(start) {
let b = table.bounds;
dbgjs!(format!("table: {:?}", table));
dbgjs!(format!("b: {:?}", b));
dbgjs!(format!(
"start == end
&& table.show_ui
&& table.show_name
&& start.x >= b.min.x
&& start.x <= b.max.x
&& start.y == b.min.y: {:?}",
start == end
&& table.show_ui
&& table.show_name
&& start.x >= b.min.x
&& start.x <= b.max.x
&& start.y == b.min.y
));
let adjust_for_name = if table.show_ui && table.show_name {
1
} else {
0
};
let adjust_for_columns = if table.show_ui && table.show_columns {
1
} else {
0
};

// if we're in the name cell of the table, then we should return the table ref
if start == end
Expand Down Expand Up @@ -80,11 +71,6 @@ impl CellRefRange {
});
}

dbgjs!(format!(
"start.x < b.min.x || end.x > b.max.x: {:?}",
start.x < b.min.x || end.x > b.max.x
));

// if the x value is outside the table, then it's not a table ref
if start.x < b.min.x || end.x > b.max.x {
return None;
Expand All @@ -103,22 +89,11 @@ impl CellRefRange {
ColRange::ColRange(col1_name, col2_name)
};

dbgjs!(format!(
"table.show_ui
&& table.show_columns
&& start.y == b.min.y + (if table.show_name {{ 1 }} else {{ 0 }})
&& end.y == b.min.y + (if table.show_name {{ 1 }} else {{ 0 }}): {:?}",
table.show_ui
&& table.show_columns
&& start.y == b.min.y + (if table.show_name { 1 } else { 0 })
&& end.y == b.min.y + (if table.show_name { 1 } else { 0 })
));

// only column headers
if table.show_ui
&& table.show_columns
&& start.y == b.min.y + (if table.show_name { 1 } else { 0 })
&& end.y == b.min.y + (if table.show_name { 1 } else { 0 })
&& start.y == b.min.y + adjust_for_name
&& end.y == b.min.y + adjust_for_name
{
return Some(CellRefRange::Table {
range: TableRef {
Expand All @@ -132,20 +107,7 @@ impl CellRefRange {
}

// only data
if start.y
== b.min.y
+ (if table.show_ui && table.show_name {
1
} else {
0
})
+ (if table.show_ui && table.show_columns {
1
} else {
0
})
&& end.y == b.max.y
{
if start.y == b.min.y + adjust_for_name + adjust_for_columns && end.y == b.max.y {
return Some(CellRefRange::Table {
range: TableRef {
table_name: table.table_name.clone(),
Expand All @@ -157,29 +119,11 @@ impl CellRefRange {
});
}

dbgjs!(format!(
"start.y
== b.min.y
+ (if table.show_ui && table.show_name {{ 1 }} else {{ 0 }}): {:?}",
start.y
== b.min.y
+ (if table.show_ui && table.show_name {
1
} else {
0
})
));

// data and column headers
if start.y
== b.min.y
+ (if table.show_ui && table.show_name {
1
} else {
0
})
&& end.y == b.max.y
{
let full_table = start.y == b.min.y && end.y == b.max.y;
let data_and_headers = start.y == b.min.y + adjust_for_name && end.y == b.max.y;

// full table or data and column headers
if full_table || data_and_headers {
return Some(CellRefRange::Table {
range: TableRef {
table_name: table.table_name.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ impl GridController {
// easily implement cut/paste/move without resorting to this
// approach.
let mut operations = VecDeque::new();
let selection = A1Selection::from_rect(source);
let context = self.grid.a1_context();
let mut selection = A1Selection::from_rect(source);
selection.check_for_table_ref(&context);

if let Ok((cut_ops, js_clipboard)) = self.cut_to_clipboard_operations(&selection) {
operations.extend(cut_ops);

Expand Down

0 comments on commit 15d0cf3

Please sign in to comment.