123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- use crate::core::delta::operation::{EmptyAttributes, Operation, OperationAttributes};
- // pub type RichTextOpBuilder = OperationsBuilder<TextAttributes>;
- pub type PlainTextOpBuilder = OperationsBuilder<EmptyAttributes>;
- #[derive(Default)]
- pub struct OperationsBuilder<T: OperationAttributes> {
- operations: Vec<Operation<T>>,
- }
- impl<T> OperationsBuilder<T>
- where
- T: OperationAttributes,
- {
- pub fn new() -> OperationsBuilder<T> {
- OperationsBuilder::default()
- }
- pub fn retain_with_attributes(mut self, n: usize, attributes: T) -> OperationsBuilder<T> {
- let retain = Operation::retain_with_attributes(n, attributes);
- self.operations.push(retain);
- self
- }
- pub fn retain(mut self, n: usize) -> OperationsBuilder<T> {
- let retain = Operation::retain(n);
- self.operations.push(retain);
- self
- }
- pub fn delete(mut self, n: usize) -> OperationsBuilder<T> {
- self.operations.push(Operation::Delete(n));
- self
- }
- pub fn insert_with_attributes(mut self, s: &str, attributes: T) -> OperationsBuilder<T> {
- let insert = Operation::insert_with_attributes(s, attributes);
- self.operations.push(insert);
- self
- }
- pub fn insert(mut self, s: &str) -> OperationsBuilder<T> {
- let insert = Operation::insert(s);
- self.operations.push(insert);
- self
- }
- pub fn build(self) -> Vec<Operation<T>> {
- self.operations
- }
- }
|