diff options
author | 2025-01-28 06:23:38 +0100 | |
---|---|---|
committer | 2025-01-28 06:23:38 +0100 | |
commit | 87165ccd29f0e85a26774ec090d8400274c6d04e (patch) | |
tree | d057c83712b9228b787adb8ac327b25bbf95795c /graphics | |
parent | 00a048677fc43a5e3106dff17e0c1c490fdc5ce1 (diff) | |
download | iced-87165ccd29f0e85a26774ec090d8400274c6d04e.tar.gz iced-87165ccd29f0e85a26774ec090d8400274c6d04e.tar.bz2 iced-87165ccd29f0e85a26774ec090d8400274c6d04e.zip |
Introduce `LineEnding` to `editor` and fix inconsistencies
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/src/text/editor.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/graphics/src/text/editor.rs b/graphics/src/text/editor.rs index 1f1d0050..c73d189c 100644 --- a/graphics/src/text/editor.rs +++ b/graphics/src/text/editor.rs @@ -9,6 +9,7 @@ use crate::text; use cosmic_text::Edit as _; +use std::borrow::Cow; use std::fmt; use std::sync::{self, Arc}; @@ -89,11 +90,17 @@ impl editor::Editor for Editor { || (buffer.lines.len() == 1 && buffer.lines[0].text().is_empty()) } - fn line(&self, index: usize) -> Option<&str> { - self.buffer() - .lines - .get(index) - .map(cosmic_text::BufferLine::text) + fn line(&self, index: usize) -> Option<editor::Line<'_>> { + self.buffer().lines.get(index).map(|line| editor::Line { + text: Cow::Borrowed(line.text()), + ending: match line.ending() { + cosmic_text::LineEnding::Lf => editor::LineEnding::Lf, + cosmic_text::LineEnding::CrLf => editor::LineEnding::CrLf, + cosmic_text::LineEnding::Cr => editor::LineEnding::Cr, + cosmic_text::LineEnding::LfCr => editor::LineEnding::LfCr, + cosmic_text::LineEnding::None => editor::LineEnding::None, + }, + }) } fn line_count(&self) -> usize { |