mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-23 05:19:48 -04:00
chore: refactor use the prefix helper
This commit is contained in:
parent
bc3b4380f8
commit
5835b6d7c9
@ -385,16 +385,16 @@ impl<'ws> Workspace<'ws> {
|
|||||||
self.enter_dialog_mode(self.render_help_text());
|
self.enter_dialog_mode(self.render_help_text());
|
||||||
}
|
}
|
||||||
KeyCode::Char('n') if key.modifiers == KeyModifiers::CONTROL => {
|
KeyCode::Char('n') if key.modifiers == KeyModifiers::CONTROL => {
|
||||||
for _ in 1..=self.state.get_n_prefix() {
|
self.run_with_prefix(|ws: &mut Workspace<'_>| -> Result<()> {
|
||||||
self.book.select_next_sheet();
|
ws.book.select_next_sheet();
|
||||||
}
|
Ok(())
|
||||||
self.state.reset_n_prefix();
|
})?;
|
||||||
}
|
}
|
||||||
KeyCode::Char('p') if key.modifiers == KeyModifiers::CONTROL => {
|
KeyCode::Char('p') if key.modifiers == KeyModifiers::CONTROL => {
|
||||||
for _ in 1..=self.state.get_n_prefix() {
|
self.run_with_prefix(|ws: &mut Workspace<'_>| -> Result<()> {
|
||||||
self.book.select_prev_sheet();
|
ws.book.select_prev_sheet();
|
||||||
}
|
Ok(())
|
||||||
self.state.reset_n_prefix();
|
})?;
|
||||||
}
|
}
|
||||||
KeyCode::Char('s')
|
KeyCode::Char('s')
|
||||||
if key.modifiers == KeyModifiers::HYPER
|
if key.modifiers == KeyModifiers::HYPER
|
||||||
@ -403,42 +403,42 @@ impl<'ws> Workspace<'ws> {
|
|||||||
self.save_file()?;
|
self.save_file()?;
|
||||||
}
|
}
|
||||||
KeyCode::Char('l') if key.modifiers == KeyModifiers::CONTROL => {
|
KeyCode::Char('l') if key.modifiers == KeyModifiers::CONTROL => {
|
||||||
for _ in 1..=self.state.get_n_prefix() {
|
self.run_with_prefix(|ws: &mut Workspace<'_>| -> Result<()> {
|
||||||
let Address { row: _, col } = &self.book.location;
|
let Address { row: _, col } = &ws.book.location;
|
||||||
self.book
|
ws.book
|
||||||
.set_col_size(*col, self.book.get_col_size(*col)? + 1)?;
|
.set_col_size(*col, ws.book.get_col_size(*col)? + 1)?;
|
||||||
}
|
Ok(())
|
||||||
self.state.reset_n_prefix();
|
})?;
|
||||||
}
|
}
|
||||||
KeyCode::Char('h') if key.modifiers == KeyModifiers::CONTROL => {
|
KeyCode::Char('h') if key.modifiers == KeyModifiers::CONTROL => {
|
||||||
for _ in 1..=self.state.get_n_prefix() {
|
self.run_with_prefix(|ws: &mut Workspace<'_>| -> Result<()> {
|
||||||
let Address { row: _, col } = &self.book.location;
|
let Address { row: _, col } = &ws.book.location;
|
||||||
let curr_size = self.book.get_col_size(*col)?;
|
let curr_size = ws.book.get_col_size(*col)?;
|
||||||
if curr_size > 1 {
|
if curr_size > 1 {
|
||||||
self.book.set_col_size(*col, curr_size - 1)?;
|
ws.book.set_col_size(*col, curr_size - 1)?;
|
||||||
}
|
}
|
||||||
}
|
Ok(())
|
||||||
self.state.reset_n_prefix();
|
})?;
|
||||||
}
|
}
|
||||||
KeyCode::Char('r') if key.modifiers == KeyModifiers::CONTROL => {
|
KeyCode::Char('r') if key.modifiers == KeyModifiers::CONTROL => {
|
||||||
for _ in 1..=self.state.get_n_prefix() {
|
self.run_with_prefix(|ws: &mut Workspace<'_>| -> Result<()> {
|
||||||
let (row_count, _) = self.book.get_size()?;
|
let (row_count, _) = ws.book.get_size()?;
|
||||||
self.book.update_entry(
|
ws.book.update_entry(
|
||||||
&Address {
|
&Address {
|
||||||
row: row_count + 1,
|
row: row_count + 1,
|
||||||
col: 1,
|
col: 1,
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
)?;
|
)?;
|
||||||
let (row, _) = self.book.get_size()?;
|
let (row, _) = ws.book.get_size()?;
|
||||||
let mut loc = self.book.location.clone();
|
let mut loc = ws.book.location.clone();
|
||||||
if loc.row < row as usize {
|
if loc.row < row as usize {
|
||||||
loc.row = row as usize;
|
loc.row = row as usize;
|
||||||
self.book.move_to(&loc)?;
|
ws.book.move_to(&loc)?;
|
||||||
}
|
}
|
||||||
self.handle_movement_change();
|
ws.handle_movement_change();
|
||||||
}
|
Ok(())
|
||||||
self.state.reset_n_prefix();
|
})?;
|
||||||
}
|
}
|
||||||
KeyCode::Char('q') => {
|
KeyCode::Char('q') => {
|
||||||
return Ok(Some(ExitCode::SUCCESS));
|
return Ok(Some(ExitCode::SUCCESS));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user