1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use tree_sitter::{Node, Tree};
use crate::editor::Editor;
use crate::id::NodeId;
/// An [Editor] that replaces the text of a single [Node].
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Replace {
pub id: NodeId,
pub bytes: Vec<u8>,
}
impl Editor for Replace {
fn has_edit(&self, _tree: &Tree, node: &Node) -> bool {
self.id.is(node)
}
fn edit(&self, _source: &[u8], tree: &Tree, node: &Node) -> Vec<u8> {
debug_assert!(self.has_edit(tree, node));
self.bytes.clone()
}
}