Compare commits
4 Commits
ea2e633d7d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9de22b9680 | |||
| 3f336578f5 | |||
| 5fbff13428 | |||
| 7a23ee5bc0 |
@@ -19,7 +19,7 @@ use crate::app::{
|
||||
clipboard::Clipboard,
|
||||
error_msg::StatusMessage,
|
||||
logic::{
|
||||
calc::{Grid, get_header_size},
|
||||
calc::{Grid, LEN, get_header_size},
|
||||
cell::CellType,
|
||||
},
|
||||
mode::Mode,
|
||||
@@ -124,6 +124,11 @@ impl Widget for &App {
|
||||
y_idx = y as usize - 1 + self.screen.scroll_y();
|
||||
}
|
||||
|
||||
// don't render non-accessible cells
|
||||
if x_idx > LEN-1 {
|
||||
continue;
|
||||
}
|
||||
|
||||
const ORANGE1: Color = Color::Rgb(200, 160, 0);
|
||||
const ORANGE2: Color = Color::Rgb(180, 130, 0);
|
||||
|
||||
|
||||
@@ -763,14 +763,16 @@ fn fn_of_fn() {
|
||||
grid.set_cell("C0", "=A0+B0".to_string());
|
||||
grid.set_cell("D0", "=C0*2".to_string());
|
||||
|
||||
if let Some(cell) = grid.get_cell("D0") {
|
||||
let cell = grid.get_cell("D0");
|
||||
assert!(cell.is_some());
|
||||
|
||||
if let Some(cell) = cell {
|
||||
let res = grid.evaluate(&cell.to_string());
|
||||
|
||||
assert!(res.is_ok());
|
||||
assert_eq!(res.unwrap(), (6.).into());
|
||||
return;
|
||||
}
|
||||
panic!("Cell not found");
|
||||
}
|
||||
|
||||
// Two cells that have a circular dependency to solve for a value
|
||||
@@ -780,12 +782,14 @@ fn circular_reference_cells() {
|
||||
grid.set_cell("A0", "=B0".to_string());
|
||||
grid.set_cell("B0", "=A0".to_string());
|
||||
|
||||
if let Some(cell) = grid.get_cell("A0") {
|
||||
let cell = grid.get_cell("A0");
|
||||
assert!(cell.is_some());
|
||||
|
||||
if let Some(cell) = cell {
|
||||
let res = grid.evaluate(&cell.to_string());
|
||||
assert!(res.is_err());
|
||||
return;
|
||||
}
|
||||
panic!("Cell not found");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -188,7 +188,14 @@ impl<'a> Context for CallbackContext<'a> {
|
||||
return None;
|
||||
}
|
||||
|
||||
e => panic!("> Error {e}\n> Equation: '{eq}'"),
|
||||
e => {
|
||||
let msg = format!("> Error {e}\n> Equation: '{eq}'");
|
||||
#[cfg(debug_assertions)]
|
||||
panic!("{msg}");
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
eprintln!("{msg}");
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,13 +273,13 @@ impl Mode {
|
||||
// Go to end of row
|
||||
'$' => {
|
||||
let (_, y) = app.grid.cursor();
|
||||
app.grid.mv_cursor_to(super::logic::calc::LEN, y);
|
||||
app.grid.mv_cursor_to(super::logic::calc::LEN-1, y);
|
||||
return;
|
||||
}
|
||||
// Go to bottom of column
|
||||
'G' => {
|
||||
let (x, _) = app.grid.cursor();
|
||||
app.grid.mv_cursor_to(x, super::logic::calc::LEN);
|
||||
app.grid.mv_cursor_to(x, super::logic::calc::LEN-1);
|
||||
return;
|
||||
}
|
||||
// edit cell
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{collections::HashMap, sync::RwLock};
|
||||
use std::{cmp::min, collections::HashMap, sync::RwLock};
|
||||
|
||||
use ratatui::prelude;
|
||||
|
||||
@@ -123,22 +123,12 @@ impl ScreenSpace {
|
||||
l.1 = area.height as usize;
|
||||
}
|
||||
|
||||
// let width = (area.width as usize + calc::get_header_size() -1) / self.get_cell_width(vars);
|
||||
let width = area.width as usize / self.get_cell_width(vars);
|
||||
let width = (area.width as usize / self.get_cell_width(vars)) + 1;
|
||||
let height = area.height as usize / self.get_cell_height(vars);
|
||||
|
||||
let x_max =
|
||||
if width > LEN {
|
||||
LEN - 1
|
||||
} else {
|
||||
width
|
||||
};
|
||||
let y_max =
|
||||
if height > LEN {
|
||||
LEN - 1
|
||||
} else {
|
||||
height
|
||||
};
|
||||
let x_max = min(LEN-1, width);
|
||||
let y_max = min(LEN-1, height);
|
||||
|
||||
(x_max as u16, y_max as u16)
|
||||
}
|
||||
|
||||
@@ -152,7 +142,7 @@ fn fit_cells() {
|
||||
app.vars.insert("height".to_string(), 1.to_string());
|
||||
|
||||
let (x,y) = app.screen.how_many_cells_fit_in(&prelude::Rect::new(0, 0, 181, 14), &app.vars);
|
||||
assert_eq!(x, 18);
|
||||
assert_eq!(x, 19);
|
||||
assert_eq!(y, 14);
|
||||
}
|
||||
|
||||
@@ -166,7 +156,7 @@ fn scroll() {
|
||||
// We have to check how many cells fit, because screen learns the width
|
||||
// of the area by rumour here.
|
||||
let (x,y) = app.screen.how_many_cells_fit_in(&prelude::Rect::new(0, 0, 181, 14), &app.vars);
|
||||
assert_eq!(x, 18);
|
||||
assert_eq!(x, 19);
|
||||
assert_eq!(y, 14);
|
||||
|
||||
// we aren't scrolled at all yet
|
||||
|
||||
Reference in New Issue
Block a user