diff --git a/crates/tek_core/src/focus.rs b/crates/tek_core/src/focus.rs index 74f9c3eb..395980c7 100644 --- a/crates/tek_core/src/focus.rs +++ b/crates/tek_core/src/focus.rs @@ -106,30 +106,61 @@ pub trait FocusGrid: HasFocus { self.focus_layout()[y][x] } fn focus_update (&mut self) { - self.focus_to(self.focus_current()) + self.focus_to(self.focus_current()); + self.focus_updated() } fn focus_up (&mut self) { - let layout = self.focus_layout(); - let (x, y) = self.focus_cursor(); - let next_y = if y == 0 { layout.len().saturating_sub(1) } else { y - 1 }; - let next_x = if layout[y].len() == layout[next_y].len() { x } else { - ((x as f32 / layout[y].len() as f32) * layout[next_y].len() as f32) as usize - }; - *self.focus_cursor_mut() = (next_x, next_y); + let original_focused = self.focused(); + let (_, original_y) = self.focus_cursor(); + loop { + let (x, y) = self.focus_cursor(); + let next_y = if y == 0 { + self.focus_layout().len().saturating_sub(1) + } else { + y - 1 + }; + if next_y == original_y { + break + } + let next_x = if self.focus_layout()[y].len() == self.focus_layout()[next_y].len() { + x + } else { + ((x as f32 / self.focus_layout()[original_y].len() as f32) * self.focus_layout()[next_y].len() as f32) as usize + }; + *self.focus_cursor_mut() = (next_x, next_y); + if self.focus_current() != original_focused { + break + } + } self.focus_update(); } fn focus_down (&mut self) { - let layout = self.focus_layout(); - let (x, y) = self.focus_cursor(); - let next_y = if y >= layout.len().saturating_sub(1) { 0 } else { y + 1 }; - let next_x = if layout[y].len() == layout[next_y].len() { x } else { - ((x as f32 / layout[y].len() as f32) * layout[next_y].len() as f32) as usize - }; - *self.focus_cursor_mut() = (next_x, next_y); + let original_focused = self.focused(); + let (_, original_y) = self.focus_cursor(); + loop { + let (x, y) = self.focus_cursor(); + let next_y = if y >= self.focus_layout().len().saturating_sub(1) { + 0 + } else { + y + 1 + }; + if next_y == original_y { + break + } + let next_x = if self.focus_layout()[y].len() == self.focus_layout()[next_y].len() { + x + } else { + ((x as f32 / self.focus_layout()[original_y].len() as f32) * self.focus_layout()[next_y].len() as f32) as usize + }; + *self.focus_cursor_mut() = (next_x, next_y); + if self.focus_current() != original_focused { + break + } + } self.focus_update(); } fn focus_left (&mut self) { - let focused = self.focused(); + let original_focused = self.focused(); let (original_x, y) = self.focus_cursor(); loop { let x = self.focus_cursor().0; @@ -142,14 +173,14 @@ pub trait FocusGrid: HasFocus { break } *self.focus_cursor_mut() = (next_x, y); - if self.focus_current() != focused { + if self.focus_current() != original_focused { break } } self.focus_update(); } fn focus_right (&mut self) { - let focused = self.focused(); + let original_focused = self.focused(); let (original_x, y) = self.focus_cursor(); loop { let x = self.focus_cursor().0; @@ -162,7 +193,7 @@ pub trait FocusGrid: HasFocus { break } self.focus_cursor_mut().0 = next_x; - if self.focus_current() != focused { + if self.focus_current() != original_focused { break } } diff --git a/crates/tek_core/src/space.rs b/crates/tek_core/src/space.rs index 1081d800..80384a61 100644 --- a/crates/tek_core/src/space.rs +++ b/crates/tek_core/src/space.rs @@ -854,6 +854,15 @@ where }) } } +#[macro_export] macro_rules! col_up { + ($($expr:expr),* $(,)?) => { Stack::down(move|add|{ $(add(&$expr)?;)* Ok(()) }) }; + ($pat:pat in $collection:expr => $item:expr) => { + Stack::up(move |add|{ + for $pat in $collection { add(&$item)?; } + Ok(()) + }) + } +} #[macro_export] macro_rules! row { ($($expr:expr),* $(,)?) => { Stack::right(move|add|{ $(add(&$expr)?;)* Ok(()) }) }; ($pat:pat in $collection:expr => $item:expr) => {