Skip to main content

vvv_engine/protocol/intent/
rewrite.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{Selection, Template};
4use vvv_core::Query;
5
6/// The rewrite `intent` makes of `matches` already found: a caller that
7/// keeps the matches (the picker, showing before and after) searches once.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct RewriteOf {
10    pub intent: RewriteIntent,
11    pub matches: Vec<crate::Match>,
12}
13
14/// Replace every selected match of `query` with `template`.
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct RewriteIntent {
17    pub query: Query,
18    pub template: Template,
19    #[serde(default, skip_serializing_if = "Selection::is_all")]
20    pub selection: Selection,
21}
22
23impl RewriteIntent {
24    pub fn new(query: Query, template: impl Into<Template>) -> Self {
25        Self {
26            query,
27            template: template.into(),
28            selection: Selection::All,
29        }
30    }
31
32    pub fn selecting(mut self, selection: Selection) -> Self {
33        self.selection = selection;
34        self
35    }
36}