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:
Jeremy Soller 2024-04-30 12:12:25 -06:00 committed by GitHub
parent ff5501d9a3
commit 0cfd9b64ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 194 additions and 15 deletions

View file

@ -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 {