wip: styling: use ctrl-i or ctrl-b

This commit is contained in:
Jeremy Wall 2025-02-26 18:21:19 -05:00
parent 8da0ebda4e
commit dae3d71c54
2 changed files with 44 additions and 13 deletions

View File

@ -669,6 +669,30 @@ impl<'ws> Workspace<'ws> {
self.state.reset_n_prefix();
self.state.char_queue.clear();
}
KeyCode::Char('b') if key.modifiers.contains(KeyModifiers::CONTROL) => {
let address = self.book.location.clone();
self.book.set_cell_style(
&[("font.b", "true")],
&Area {
sheet: self.book.current_sheet,
row: address.row as i32,
column: address.col as i32,
width: 1,
height: 1,
})?;
}
KeyCode::Char('i') if key.modifiers.contains(KeyModifiers::CONTROL) => {
let address = self.book.location.clone();
self.book.set_cell_style(
&[("font.i", "true")],
&Area {
sheet: self.book.current_sheet,
row: address.row as i32,
column: address.col as i32,
width: 1,
height: 1,
})?;
}
KeyCode::Char(d) if d.is_ascii_digit() => {
self.handle_numeric_prefix(d);
}
@ -831,18 +855,6 @@ impl<'ws> Workspace<'ws> {
self.state.char_queue.push('g');
}
}
KeyCode::Char('b') => {
let address = self.book.location.clone();
self.book.set_cell_style(
&[("font.b", "true")],
&Area {
sheet: self.book.current_sheet,
row: address.row as i32,
column: address.col as i32,
width: 1,
height: 1,
})?;
}
_ => {
// noop
self.state.char_queue.clear();

View File

@ -1291,7 +1291,7 @@ fn test_bold_text() {
.expect("Failed to get style");
assert!(!before_style.font.b);
script()
.char('b')
.ctrl('b')
.run(&mut ws)
.expect("Unable to run script");
let style = ws
@ -1301,6 +1301,25 @@ fn test_bold_text() {
assert!(style.font.b);
}
#[test]
fn test_italic_text() {
let mut ws = new_workspace();
let before_style = ws
.book
.get_cell_style(0, &Address { row: 1, col: 1 })
.expect("Failed to get style");
assert!(!before_style.font.i);
script()
.ctrl('i')
.run(&mut ws)
.expect("Unable to run script");
let style = ws
.book
.get_cell_style(0, &Address { row: 1, col: 1 })
.expect("Failed to get style");
assert!(style.font.i);
}
fn new_workspace<'a>() -> Workspace<'a> {
Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook")
}