mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-22 13:00:22 -04:00
wip: styling: resusable toggle func
This commit is contained in:
parent
ba5ea3c627
commit
4623a911f4
@ -670,10 +670,14 @@ impl<'ws> Workspace<'ws> {
|
|||||||
self.state.char_queue.clear();
|
self.state.char_queue.clear();
|
||||||
}
|
}
|
||||||
KeyCode::Char('b') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
KeyCode::Char('b') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||||
self.toggle_bold()?;
|
let address = self.book.location.clone();
|
||||||
|
let style = self.book.get_cell_style(self.book.current_sheet, &address).map(|s| s.font.b);
|
||||||
|
self.toggle_bool_style(style, "font.b", &address)?;
|
||||||
}
|
}
|
||||||
KeyCode::Char('i') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
KeyCode::Char('i') if key.modifiers.contains(KeyModifiers::CONTROL) => {
|
||||||
self.toggle_italic()?;
|
let address = self.book.location.clone();
|
||||||
|
let style = self.book.get_cell_style(self.book.current_sheet, &address).map(|s| s.font.i);
|
||||||
|
self.toggle_bool_style(style, "font.i", &address)?;
|
||||||
}
|
}
|
||||||
KeyCode::Char(d) if d.is_ascii_digit() => {
|
KeyCode::Char(d) if d.is_ascii_digit() => {
|
||||||
self.handle_numeric_prefix(d);
|
self.handle_numeric_prefix(d);
|
||||||
@ -846,34 +850,14 @@ impl<'ws> Workspace<'ws> {
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_italic(&mut self) -> Result<(), anyhow::Error> {
|
fn toggle_bool_style(&mut self, current_val: Option<bool>, path: &str, address: &Address) -> Result<(), anyhow::Error> {
|
||||||
let address = self.book.location.clone();
|
let value = if let Some(b_val) = current_val {
|
||||||
let value = if let Some(style) = self.book.get_cell_style(self.book.current_sheet, &address) {
|
if b_val { "false" } else { "true" }
|
||||||
if style.font.i { "false" } else { "true" }
|
|
||||||
} else {
|
} else {
|
||||||
"true"
|
"true"
|
||||||
};
|
};
|
||||||
self.book.set_cell_style(
|
self.book.set_cell_style(
|
||||||
&[("font.i", value)],
|
&[(path, value)],
|
||||||
&Area {
|
|
||||||
sheet: self.book.current_sheet,
|
|
||||||
row: address.row as i32,
|
|
||||||
column: address.col as i32,
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
})?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn toggle_bold(&mut self) -> Result<(), anyhow::Error> {
|
|
||||||
let address = self.book.location.clone();
|
|
||||||
let value = if let Some(style) = self.book.get_cell_style(self.book.current_sheet, &address) {
|
|
||||||
if style.font.b { "false" } else { "true" }
|
|
||||||
} else {
|
|
||||||
"true"
|
|
||||||
};
|
|
||||||
self.book.set_cell_style(
|
|
||||||
&[("font.b", value)],
|
|
||||||
&Area {
|
&Area {
|
||||||
sheet: self.book.current_sheet,
|
sheet: self.book.current_sheet,
|
||||||
row: address.row as i32,
|
row: address.row as i32,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user