mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-23 13:29:48 -04:00
wip: ui: edit mode enhancements
This commit is contained in:
parent
0fa37e2504
commit
770dc1dbc3
@ -1,3 +0,0 @@
|
||||
pi,3^5,"ref(0,0)",-(1/0)
|
||||
12%5,"pow(3,5)",0/NaN,"""Apollo"""
|
||||
A1+A2,"if(true , sqrt(25),round(if(false,1.1,2.5)))",D2+1969,
|
|
BIN
examples/test.xlsx
Normal file
BIN
examples/test.xlsx
Normal file
Binary file not shown.
@ -7,7 +7,7 @@ use ironcalc::{
|
||||
worksheet::WorksheetDimension,
|
||||
Model,
|
||||
},
|
||||
export::save_to_xlsx,
|
||||
export::save_xlsx_to_writer,
|
||||
import::load_from_xlsx,
|
||||
};
|
||||
|
||||
@ -51,7 +51,11 @@ impl Book {
|
||||
|
||||
/// Save book to an xlsx file.
|
||||
pub fn save_to_xlsx(&self, path: &str) -> Result<()> {
|
||||
save_to_xlsx(&self.model, path)?;
|
||||
// TODO(zaphar): Currently overwrites. Should we prompty in this case?
|
||||
let file_path = std::path::Path::new(path);
|
||||
let file = std::fs::File::create(file_path)?;
|
||||
let writer = std::io::BufWriter::new(file);
|
||||
save_xlsx_to_writer(&self.model, writer)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -156,14 +156,9 @@ impl<'ws> Workspace<'ws> {
|
||||
fn handle_edit_input(&mut self, key: event::KeyEvent) -> Result<Option<ExitCode>> {
|
||||
if key.kind == KeyEventKind::Press {
|
||||
if let KeyCode::Esc = key.code {
|
||||
self.state.modality = Modality::Navigate;
|
||||
self.text_area.set_cursor_line_style(Style::default());
|
||||
self.text_area.set_cursor_style(Style::default());
|
||||
let contents = self.text_area.lines().join("\n");
|
||||
if self.dirty {
|
||||
self.book.edit_current_cell(contents)?;
|
||||
}
|
||||
return Ok(None);
|
||||
self.exit_edit_mode()?;
|
||||
} else if let KeyCode::Enter = key.code {
|
||||
self.exit_edit_mode()?;
|
||||
}
|
||||
}
|
||||
// TODO(zaphar): Some specialized editing keybinds
|
||||
@ -176,6 +171,18 @@ impl<'ws> Workspace<'ws> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn exit_edit_mode(&mut self) -> Result<(), anyhow::Error> {
|
||||
self.state.modality = Modality::Navigate;
|
||||
self.text_area.set_cursor_line_style(Style::default());
|
||||
self.text_area.set_cursor_style(Style::default());
|
||||
let contents = self.text_area.lines().join("\n");
|
||||
if self.dirty {
|
||||
self.book.edit_current_cell(contents)?;
|
||||
self.book.evaluate();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_navigation_input(&mut self, key: event::KeyEvent) -> Result<Option<ExitCode>> {
|
||||
if key.kind == KeyEventKind::Press {
|
||||
match key.code {
|
||||
|
Loading…
x
Reference in New Issue
Block a user