add efficient is_empty method to text_editor::Content

This commit is contained in:
Michael Freeborn 2025-11-21 08:48:22 +00:00
parent c67f523818
commit 3da40cb05b

View file

@ -472,6 +472,17 @@ where
pub fn cursor_position(&self) -> (usize, usize) {
self.0.borrow().editor.cursor_position()
}
/// Returns whether or not the the [`Content`] is empty.
pub fn is_empty(&self) -> bool {
let editor = &self.0.borrow().editor;
match editor.line_count() {
0 => true,
1 => editor.line(0).map(|l| l.text.is_empty()).unwrap_or(true),
_ => false,
}
}
}
impl<Renderer> Clone for Content<Renderer>