Skip to content

Commit

Permalink
Add ctrl+s for saving to editor
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Apr 30, 2024
1 parent a4bf932 commit 2f467d8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion examples/editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmic_text::{
Action, Attrs, Buffer, Edit, Family, FontSystem, Metrics, Motion, SwashCache, SyntaxEditor,
SyntaxSystem,
};
use std::{env, num::NonZeroU32, rc::Rc, slice};
use std::{env, fs, num::NonZeroU32, rc::Rc, slice};
use tiny_skia::{Paint, PixmapMut, Rect, Transform};
use winit::{
dpi::PhysicalPosition,
Expand Down Expand Up @@ -248,6 +248,17 @@ fn main() {
});
}
}
"s" => {
let mut text = String::new();
editor.with_buffer(|buffer| {
for line in buffer.lines.iter() {
text.push_str(line.text());
text.push_str(line.ending().as_str());
}
});
fs::write(&path, &text).unwrap();
log::info!("saved {:?}", path);
}
_ => {}
}
} else {
Expand Down

0 comments on commit 2f467d8

Please sign in to comment.