text-document-search 1.10.2

Find and replace use cases for text-document
Documentation
// Generated by Qleany v1.5.1 from feature_dtos.tera

use common::format_runs::ReplaceFormatPolicy;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct FindTextDto {
    pub query: String,
    pub case_sensitive: bool,
    pub whole_word: bool,
    /// `false` (the default) folds diacritics, ligatures and Arabic orthography, so that
    /// `aurelien` finds `Aurélien`. See `crate::folding`.
    pub diacritic_sensitive: bool,
    /// The BCP-47 tag of the text being searched. Only Turkish and Azerbaijani change how
    /// text *folds*; anything else — including an empty or malformed tag — is untailored.
    pub language: String,
    pub use_regex: bool,
    pub search_backward: bool,
    pub start_position: i64,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct FindResultDto {
    pub found: bool,
    pub position: i64,
    pub length: i64,
    /// The text that was actually matched. Folding means the query is not it: `cafe` matches
    /// `café`. Sliced from the text the search ran on, so a caller never has to.
    pub matched_text: String,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct FindAllDto {
    pub query: String,
    pub case_sensitive: bool,
    pub whole_word: bool,
    /// See [`FindTextDto::diacritic_sensitive`].
    pub diacritic_sensitive: bool,
    /// See [`FindTextDto::language`].
    pub language: String,
    pub use_regex: bool,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct FindAllResultDto {
    pub positions: Vec<i64>,
    pub lengths: Vec<i64>,
    /// The matched **text** of each occurrence, sliced from the document's own search text.
    ///
    /// Returned so a caller never has to slice it themselves. The tempting whole-document
    /// string to slice instead is `to_plain_text`, which is the human-readable view and does
    /// **not** carry the `U+FFFC` anchor an embedded table occupies — so slicing that with
    /// these offsets is wrong by two characters per preceding table. (A caller that truly
    /// needs the sliceable string can ask for [`AddressableTextResultDto`], which shares
    /// this offset space.)
    pub matched_texts: Vec<String>,
    pub count: i64,
}
/// The document's **addressable text**: the exact string every document offset is an
/// index into — `find_all`/`find_text` match positions, `replace_ranges` ranges, a
/// block's `document_position`, a cursor or selection offset from an editor widget.
///
/// Built by the same code path `find_all` uses to build the text it searches
/// (`build_full_text`), so the two cannot diverge. This is **not** the export view:
/// an embedded table occupies its `U+FFFC` anchor here (one char plus its `\n`
/// separator), exactly as the document holds it, where `to_plain_text` omits it.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct AddressableTextResultDto {
    pub text: String,
}

#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct ReplaceTextDto {
    pub query: String,
    pub replacement: String,
    pub case_sensitive: bool,
    pub whole_word: bool,
    /// See [`FindTextDto::diacritic_sensitive`].
    pub diacritic_sensitive: bool,
    /// See [`FindTextDto::language`].
    pub language: String,
    pub use_regex: bool,
    pub replace_all: bool,
    /// What the replacement text wears where it overwrites formatted prose.
    ///
    /// Defaults to the historical behaviour (`InheritPreceding`), which drops the
    /// formatting under the range — fine for plain text, destructive for a rename that
    /// lands on a partly-bold name. See [`ReplaceFormatPolicy`].
    pub format_policy: ReplaceFormatPolicy,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct ReplaceResultDto {
    pub replacements_count: i64,
    pub skipped_cross_block: i64,
}

/// An explicit set of ranges to replace, each with its own replacement text.
///
/// The three lists are **parallel** and must be the same length: range `i` is
/// `positions[i] .. positions[i] + lengths[i]`, replaced by `replacements[i]`. Positions
/// are **char** offsets into the document's search text.
///
/// A list of structs is not expressible in a DTO here (every field is a scalar or a list
/// of scalars — `FindAllResultDto` uses the same parallel-list idiom), so the public API
/// exposes the typed `ReplaceRange` shape and converts at this boundary.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct ReplaceRangesDto {
    pub positions: Vec<i64>,
    pub lengths: Vec<i64>,
    pub replacements: Vec<String>,
    /// What each replacement wears where it overwrites formatted prose. See
    /// [`ReplaceFormatPolicy`].
    pub format_policy: ReplaceFormatPolicy,
}

#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct ReplaceRangesResultDto {
    pub replacements_count: i64,
    /// Ranges that straddled a block boundary. A block is the unit an edit is applied to,
    /// so a range crossing two of them is refused rather than half-applied.
    pub skipped_cross_block: i64,
    /// Ranges that overlapped an earlier one. Two edits to the same characters cannot both
    /// be honoured; the earlier range wins and the later is reported, never silently
    /// dropped.
    pub skipped_overlapping: i64,
}