Skip to main content

FindSession

Struct FindSession 

Source
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

Source

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.

Source

pub fn session_id(&self) -> SessionId

The document session this layer owns — put it in a view’s HighlightMask to render it there.

Source

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.

Source

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.

Source

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.

Source

pub fn match_count(&self) -> usize

How many matches the last query found.

Source

pub fn current_index(&self) -> usize

The current match’s 0-based index (0 when the reader is not standing on one).

Source

pub fn current_match(&self) -> Option<FindMatch>

The current match, if the reader is standing on one of this document’s.

Source

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.

Source

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.

Source

pub fn clear(&mut self)

Clear all highlighting (the query went away, or the banner closed).

Trait Implementations§

Source§

impl Drop for FindSession

Source§

fn drop(&mut self)

Retire the session so a closed find banner leaves no highlight layer behind on the shared document.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more