From 3da40cb05b42da32676acfa56febe381636c5404 Mon Sep 17 00:00:00 2001 From: Michael Freeborn Date: Fri, 21 Nov 2025 08:48:22 +0000 Subject: [PATCH] add efficient `is_empty` method to `text_editor::Content` --- widget/src/text_editor.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 6c5efb3f..6a48e3fa 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -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 Clone for Content