diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs index 857d8677c0..6afeec127c 100644 --- a/examples/editor/src/main.rs +++ b/examples/editor/src/main.rs @@ -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 {