diff options
Diffstat (limited to 'src/widgets/sheetview')
| -rw-r--r-- | src/widgets/sheetview/mod.rs | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/src/widgets/sheetview/mod.rs b/src/widgets/sheetview/mod.rs index 6ef8125..f81edab 100644 --- a/src/widgets/sheetview/mod.rs +++ b/src/widgets/sheetview/mod.rs @@ -9,7 +9,7 @@ use ratatui::{ }; use crate::{ - config::{theme::style, GlobalConfig}, + config::GlobalConfig, lua, sheet::{ cell::Cell, @@ -23,7 +23,9 @@ use super::{luaeditor::LuaEditor, statusbar::StatusBar}; const DEFAULT_COLUMN_WIDTH: u16 = 10; +#[derive(Default)] enum SheetViewMode { + #[default] Normal, Insert, Visual, @@ -34,6 +36,7 @@ enum SheetViewMode { EditorError(String), } +#[derive(Default)] pub struct SheetView { bar: StatusBar, sheet: SheetId, @@ -153,7 +156,7 @@ impl SheetView { KeyCode::Char('h') => self.move_cursor_by((0, -1)), KeyCode::Char('l') => self.move_cursor_by((0, 1)), KeyCode::Char('v') => { - self.selection_anchor = Some(self.cursor.clone()); + self.selection_anchor = Some(self.cursor); self.mode = SheetViewMode::Visual } KeyCode::Char('s') => { @@ -175,7 +178,7 @@ impl SheetView { let lock = Register::get(self.sheet).unwrap(); let mut sheet = lock.write().unwrap(); - if let Some(_) = self.selection_anchor { + if self.selection_anchor.is_some() { self.selection().iter().map(|(r, c)| (*r, *c)).collect() } else { vec![self.cursor] @@ -235,12 +238,10 @@ impl SheetView { KeyCode::Enter => { if let Err(error) = lua::get().load(self.bar.input().unwrap_or("")).exec() { self.mode = SheetViewMode::CommandError(error.to_string()) + } else if self.selection_anchor.is_some() { + self.mode = SheetViewMode::Visual; } else { - if self.selection_anchor.is_some() { - self.mode = SheetViewMode::Visual; - } else { - self.mode = SheetViewMode::Normal; - } + self.mode = SheetViewMode::Normal; } self.bar.set_input_mode(false); @@ -271,7 +272,7 @@ impl SheetView { let mut cells = Vec::new(); - if let Some(_) = self.selection_anchor { + if self.selection_anchor.is_some() { cells = self .selection() .iter() @@ -311,26 +312,18 @@ impl SheetView { } fn is_editor_visible(&self) -> bool { - match self.mode { - SheetViewMode::Script - | SheetViewMode::Processing(_) - | SheetViewMode::EditorError(_) => true, - _ => false, - } + matches!( + self.mode, + SheetViewMode::Script | SheetViewMode::Processing(_) | SheetViewMode::EditorError(_), + ) } fn is_error_window_visible(&self) -> bool { - match self.mode { - SheetViewMode::EditorError(_) => true, - _ => false, - } + matches!(self.mode, SheetViewMode::EditorError(_)) } fn is_progress_visible(&self) -> bool { - match self.mode { - SheetViewMode::Processing(_) => true, - _ => false, - } + matches!(self.mode, SheetViewMode::Processing(_)) } fn areas(&self, area: Rect) -> (Rect, Rect, Rect, Rect, Rect) { @@ -428,19 +421,19 @@ impl Widget for &mut SheetView { theme .cursor .get(cell_ref, &lua::get()) - .unwrap_or(style::Style::new()) + .unwrap_or_default() .apply(cell.to_line()) } else if self.is_in_selection(cell_pos_y, cell_pos_x) { theme .selection .get(cell_ref, &lua::get()) - .unwrap_or(style::Style::new()) + .unwrap_or_default() .apply(cell.to_line()) } else { theme .cell .get(cell_ref, &lua::get()) - .unwrap_or(style::Style::new()) + .unwrap_or_default() .apply(cell.to_line()) }; @@ -537,7 +530,7 @@ impl Widget for &mut SheetView { ) .percent(progress as u16); - Clear::default().render(progress_area, buf); + Clear.render(progress_area, buf); gauge.render(progress_area, buf); } } |