Add text helper method for text_editor::Content

This commit is contained in:
Héctor Ramón Jiménez 2023-09-22 06:00:51 +02:00
parent af21cf8249
commit 8cc19de254
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 22 additions and 18 deletions

View file

@ -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()
}