summaryrefslogtreecommitdiffstats
path: root/widget/src/text_editor.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-09-22 06:00:51 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-09-22 06:00:51 +0200
commit8cc19de254c37d3123d5ea1b6513f1f34d35c7c8 (patch)
tree51b92985af24169acf6949ae7bf4e1ac957ca24a /widget/src/text_editor.rs
parentaf21cf82492bf7ffa1241cebae182c5916fc07d1 (diff)
downloadiced-8cc19de254c37d3123d5ea1b6513f1f34d35c7c8.tar.gz
iced-8cc19de254c37d3123d5ea1b6513f1f34d35c7c8.tar.bz2
iced-8cc19de254c37d3123d5ea1b6513f1f34d35c7c8.zip
Add `text` helper method for `text_editor::Content`
Diffstat (limited to 'widget/src/text_editor.rs')
-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()
}