pub struct SegmentedText { /* private fields */ }
Expand description
A string segmented in sequences of words, spaces, tabs and separated line breaks.
Each segment is tagged with a TextSegmentKind
and is defines as
an offset from the last segment.
Implementations§
source§impl SegmentedText
impl SegmentedText
sourcepub fn new(
text: impl Into<Txt>,
base_direction: LayoutDirection,
) -> SegmentedText
pub fn new( text: impl Into<Txt>, base_direction: LayoutDirection, ) -> SegmentedText
New segmented text from any text type.
sourcepub fn segs(&self) -> &[TextSegment]
pub fn segs(&self) -> &[TextSegment]
The text segments.
sourcepub fn seg_from_char(&self, from: usize) -> usize
pub fn seg_from_char(&self, from: usize) -> usize
Get segment index from a char index.
sourcepub fn base_direction(&self) -> LayoutDirection
pub fn base_direction(&self) -> LayoutDirection
Contextual direction.
Note that each segment can override the direction, and even the entire text can be a sequence in the opposite direction.
sourcepub fn get(&self, index: usize) -> Option<(&str, TextSegment)>
pub fn get(&self, index: usize) -> Option<(&str, TextSegment)>
Returns the text segment if index
is in bounds.
sourcepub fn get_clone(&self, index: usize) -> Option<SegmentedText>
pub fn get_clone(&self, index: usize) -> Option<SegmentedText>
Returns a clone of the text segment if index
is in bounds.
sourcepub fn into_parts(self) -> (Txt, Vec<TextSegment>, LayoutDirection)
pub fn into_parts(self) -> (Txt, Vec<TextSegment>, LayoutDirection)
Destructs self
into the text and segments.
sourcepub fn from_parts(
text: Txt,
segments: Vec<TextSegment>,
base_direction: LayoutDirection,
) -> SegmentedText
pub fn from_parts( text: Txt, segments: Vec<TextSegment>, base_direction: LayoutDirection, ) -> SegmentedText
sourcepub fn iter(&self) -> SegmentedTextIter<'_> ⓘ
pub fn iter(&self) -> SegmentedTextIter<'_> ⓘ
Segments iterator.
§Examples
for (sub_str, seg) in SegmentedText::new("Foo bar!\nBaz.", LayoutDirection::LTR).iter() {
println!("s: {sub_str:?} is a `{:?}`", seg.kind);
}
sourcepub fn text_range(&self, segs_range: Range<usize>) -> Range<usize>
pub fn text_range(&self, segs_range: Range<usize>) -> Range<usize>
Convert a segments range to a text bytes range.
sourcepub fn reorder_line_to_ltr(&self, segs_range: Range<usize>) -> Vec<usize>
pub fn reorder_line_to_ltr(&self, segs_range: Range<usize>) -> Vec<usize>
Compute a map of segments in segs_range
to their final LTR display order.
The segs_range
must be the segments of a line after line wrap.
sourcepub fn snap_char_boundary(&self, i: usize) -> usize
pub fn snap_char_boundary(&self, i: usize) -> usize
Find the nearest next char boundary from the byte index i
.
If i
is larger than the text length, returns the text length, if i
is
already a char boundary, returns i
.
sourcepub fn snap_grapheme_boundary(&self, i: usize) -> usize
pub fn snap_grapheme_boundary(&self, i: usize) -> usize
Find the nearest grapheme cluster boundary from the byte index i
.
If i
is larger than the text length, returns the text length, if i
is
already a grapheme boundary, returns i
.
sourcepub fn next_insert_index(&self, from: usize) -> usize
pub fn next_insert_index(&self, from: usize) -> usize
Find the next grapheme cluster, after from
.
The from
must be in a grapheme boundary or 0
or len
. This operation is saturating.
§Panics
Panics if from
is larger than the text length, or is not at a grapheme boundary.
sourcepub fn prev_insert_index(&self, from: usize) -> usize
pub fn prev_insert_index(&self, from: usize) -> usize
Find the previous grapheme cluster, before from
.
The from
must be in a grapheme boundary or 0
or len
. This operation is saturating.
§Panics
Panics if from
is larger than the text length, or is not at a grapheme boundary.
sourcepub fn next_word_index(&self, from: usize) -> usize
pub fn next_word_index(&self, from: usize) -> usize
Find the start of the next word or the next line-break segment, after from
.
This operation is saturating.
sourcepub fn next_word_end_index(&self, from: usize) -> usize
pub fn next_word_end_index(&self, from: usize) -> usize
Find the next word segment end or the next line-break segment end, after from
.
This operation is saturating.
sourcepub fn prev_word_index(&self, from: usize) -> usize
pub fn prev_word_index(&self, from: usize) -> usize
Find the start of the previous word segment or the previous line-break segment, before from
.
This operation is saturating.
sourcepub fn line_start_index(&self, from: usize) -> usize
pub fn line_start_index(&self, from: usize) -> usize
Find the start of the line that contains from
.
§Panics
Panics if from
is larger than the text length, or is not a char boundary.
sourcepub fn line_end_index(&self, from: usize) -> usize
pub fn line_end_index(&self, from: usize) -> usize
Find the end of the line that contains from
.
§Panics
Panics if from
is larger than the text length, or is not a char boundary.
sourcepub fn delete_range(&self, from: usize, count: u32) -> Range<usize>
pub fn delete_range(&self, from: usize, count: u32) -> Range<usize>
Find the range that must be removed to delete starting by from
a count
number of times.
Delete Del action removes the next grapheme cluster, this is different from
backspace_range
that usually only removes one character.
§Panics
Panics if from
is larger than the text length, or is not a grapheme boundary.
sourcepub fn backspace_range(&self, from: usize, count: u32) -> Range<usize>
pub fn backspace_range(&self, from: usize, count: u32) -> Range<usize>
Find the range that must be removed to backspace before from
a count
number of times.
The character at from
is not included, only the previous char is selected, with some exceptions,
the selection includes any char before zero-width-joiner (ZWJ), it also includes \r
before \n
and Emoji char before Emoji modifier or variation selector (VS16).
§Panics
Panics if from
is larger than the text length, or is not a char boundary.
Trait Implementations§
source§impl Clone for SegmentedText
impl Clone for SegmentedText
source§fn clone(&self) -> SegmentedText
fn clone(&self) -> SegmentedText
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SegmentedText
impl Debug for SegmentedText
source§impl Default for SegmentedText
impl Default for SegmentedText
source§fn default() -> SegmentedText
fn default() -> SegmentedText
source§impl PartialEq for SegmentedText
impl PartialEq for SegmentedText
impl Eq for SegmentedText
impl StructuralPartialEq for SegmentedText
Auto Trait Implementations§
impl Freeze for SegmentedText
impl RefUnwindSafe for SegmentedText
impl Send for SegmentedText
impl Sync for SegmentedText
impl Unpin for SegmentedText
impl UnwindSafe for SegmentedText
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
source§impl<T> AnyVarValue for Twhere
T: VarValue,
impl<T> AnyVarValue for Twhere
T: VarValue,
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
dyn Any
methods.source§fn clone_boxed(&self) -> Box<dyn AnyVarValue>
fn clone_boxed(&self) -> Box<dyn AnyVarValue>
source§fn clone_boxed_var(&self) -> Box<dyn AnyVar>
fn clone_boxed_var(&self) -> Box<dyn AnyVar>
LocalVar<Self>
.source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self
equals other
.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.