pub struct FindSession { /* private fields */ }Expand description
A search-highlight layer: the matches of a query, as a document range session, with the current match distinguished.
Implementations§
Source§impl FindSession
impl FindSession
Sourcepub fn new(
doc: &TextDocument,
current_format: HighlightFormat,
other_format: HighlightFormat,
) -> Self
pub fn new( doc: &TextDocument, current_format: HighlightFormat, other_format: HighlightFormat, ) -> Self
Attach a fresh, empty find session to doc. current_format styles the current match
(e.g. the editor selection colour); other_format styles the rest (e.g. a subtle
accent). Both should be paint-only (background / underline) so the highlight stays
out of the accessibility tree — a screen-reader user navigates matches by count, not by
colour.
Sourcepub fn session_id(&self) -> SessionId
pub fn session_id(&self) -> SessionId
The document session this layer owns — put it in a view’s
HighlightMask to render it there.
Sourcepub fn set_query(&mut self, query: &str, options: &FindOptions)
pub fn set_query(&mut self, query: &str, options: &FindOptions)
Re-run query and highlight every match; the first becomes current. An empty query
clears the highlighting.
Sourcepub fn set_current(&mut self, index: Option<usize>) -> Option<FindMatch>
pub fn set_current(&mut self, index: Option<usize>) -> Option<FindMatch>
Say which of this document’s matches the reader is standing on, or None for
“none of them” — the state a find spanning several documents needs for every
document but the one holding the cursor. Returns the new current match.
An index past the end is clamped to the last match, and any index at all on an
empty match set is None: a caller stepping into a document it has just re-run
cannot be asked to know how many matches it turned out to have.
Sourcepub fn refresh_if_stale(&mut self) -> bool
pub fn refresh_if_stale(&mut self) -> bool
Re-derive the matches for the stored query if an edit has staled them since the last
run. Returns true if it re-derived (so the caller can request a repaint). Cheap to
call every frame: a no-op when nothing has changed.
The current-match index is clamped, not reset — an edit should not throw away where the writer was in the match list, only re-locate the matches. A document that had no current match still has none: the reader is standing somewhere else.
Sourcepub fn match_count(&self) -> usize
pub fn match_count(&self) -> usize
How many matches the last query found.
Sourcepub fn current_index(&self) -> usize
pub fn current_index(&self) -> usize
The current match’s 0-based index (0 when the reader is not standing on one).
Sourcepub fn current_match(&self) -> Option<FindMatch>
pub fn current_match(&self) -> Option<FindMatch>
The current match, if the reader is standing on one of this document’s.
Sourcepub fn next_match(&mut self) -> Option<FindMatch>
pub fn next_match(&mut self) -> Option<FindMatch>
Advance to the next match, wrapping past the end, and return it. None if there are no
matches. From “no current match” it lands on the first — which is what stepping
into this document from the one above it means.
Sourcepub fn prev_match(&mut self) -> Option<FindMatch>
pub fn prev_match(&mut self) -> Option<FindMatch>
Step to the previous match, wrapping past the start, and return it. From “no current
match” it lands on the last, the mirror of next_match:
stepping backwards into a document arrives at its end.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for FindSession
impl !UnwindSafe for FindSession
impl Freeze for FindSession
impl Send for FindSession
impl Sync for FindSession
impl Unpin for FindSession
impl UnsafeUnpin for FindSession
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§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<T> ErasedDestructor for Twhere
T: 'static,
§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> 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