Add line ending abstraction (#250)
* Add line ending abstraction * Make Buffer::set_text use LineIter * Add ctrl+s for saving to editor
This commit is contained in:
parent
ff5501d9a3
commit
0cfd9b64ef
10 changed files with 194 additions and 15 deletions
|
|
@ -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,
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue