summaryrefslogtreecommitdiffstats
path: root/widget
diff options
context:
space:
mode:
Diffstat (limited to 'widget')
-rw-r--r--widget/src/text_editor.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs
index c142c22d..6d25967e 100644
--- a/widget/src/text_editor.rs
+++ b/widget/src/text_editor.rs
@@ -190,6 +190,27 @@ where
}
}
+ pub fn text(&self) -> String {
+ let mut text = self.lines().enumerate().fold(
+ String::new(),
+ |mut contents, (i, line)| {
+ if i > 0 {
+ contents.push('\n');
+ }
+
+ contents.push_str(&line);
+
+ contents
+ },
+ );
+
+ if !text.ends_with('\n') {
+ text.push('\n');
+ }
+
+ text
+ }
+
pub fn selection(&self) -> Option<String> {
self.0.borrow().editor.selection()
}