momentum fixes

This commit is contained in:
2025-11-13 10:01:45 -07:00
parent 7ab6b23f73
commit 6a6277f2d3
5 changed files with 107 additions and 41 deletions

View File

@@ -1,8 +1,5 @@
use std::{
fmt::Display,
fs,
io::{Read, Write},
path::PathBuf,
cmp::{max, min}, fmt::Display, fs, io::{Read, Write}, path::PathBuf
};
use evalexpr::*;
@@ -38,6 +35,24 @@ impl Grid {
self.selected_cell
}
pub fn apply_momentum(&mut self, (x, y): (i32, i32)) {
let (cx, cy) = self.cursor();
assert_eq!(0i32.saturating_add(-1), -1);
let x = (cx as i32).saturating_add(x);
let y = (cy as i32).saturating_add(y);
// make it positive
let x = max(x,0) as usize;
let y = max(y,0) as usize;
// keep it in the grid
let x = min(x, LEN-1);
let y = min(y, LEN-1);
self.mv_cursor_to(x, y);
}
pub fn mv_cursor_to(&mut self, x: usize, y: usize) {
self.selected_cell = (x,y)
}
@@ -718,7 +733,7 @@ fn ranges() {
#[test]
fn recursive_ranges() {
// recursive ranges causes weird behavior
// todo!();
todo!();
}
#[test]