TEXT SELECTION

This commit is contained in:
2025-11-21 23:56:31 -05:00
parent 246caffb34
commit 1cec56e847
10 changed files with 332 additions and 69 deletions

View File

@@ -5,7 +5,7 @@ pub use build::*;
pub use edit::*;
use crate::{prelude::*, util::MutDetect};
use cosmic_text::{Attrs, Metrics, Shaping};
use cosmic_text::{Attrs, BufferLine, Cursor, Metrics, Shaping};
use std::ops::{Deref, DerefMut};
pub const SHAPING: Shaping = Shaping::Advanced;
@@ -82,6 +82,15 @@ impl TextView {
painter.texture_within(&tex.handle, region);
region
}
pub fn content(&self) -> String {
self.buf
.lines
.iter()
.map(|l| l.text())
.collect::<Vec<_>>()
.join("\n")
}
}
impl Text {
@@ -124,6 +133,16 @@ impl Widget for Text {
}
}
pub fn sort_cursors(a: Cursor, b: Cursor) -> (Cursor, Cursor) {
let start = a.min(b);
let end = a.max(b);
(start, end)
}
pub fn edit_line(line: &mut BufferLine, text: String) {
line.set_text(text, line.ending(), line.attrs_list().clone());
}
impl Deref for Text {
type Target = TextAttrs;