Enable external change tracking

This commit is contained in:
Jeremy Soller 2023-11-13 12:37:07 -07:00
parent e942e649ed
commit 7830f4107c
No known key found for this signature in database
GPG key ID: DCFCA852D3906975
4 changed files with 253 additions and 209 deletions

View file

@ -1,5 +1,5 @@
#[cfg(not(feature = "std"))]
use alloc::string::String;
use alloc::{string::String, vec::Vec};
#[cfg(feature = "swash")]
use crate::Color;
@ -93,6 +93,17 @@ pub enum Action {
GotoLine(usize),
}
#[derive(Clone, Debug)]
pub enum ChangeItem {
Delete(Cursor, String),
Insert(Cursor, String),
}
#[derive(Clone, Debug, Default)]
pub struct Change {
items: Vec<ChangeItem>,
}
/// A trait to allow easy replacements of [`Editor`], like `SyntaxEditor`
pub trait Edit {
/// Mutably borrows `self` together with an [`FontSystem`] for more convenient methods
@ -147,6 +158,12 @@ pub trait Edit {
/// attributes, or with the previous character's attributes if None is given.
fn insert_string(&mut self, data: &str, attrs_list: Option<AttrsList>);
/// Start collecting change
fn start_change(&mut self);
/// Get completed change
fn finish_change(&mut self) -> Option<Change>;
/// Perform an [Action] on the editor
fn action(&mut self, font_system: &mut FontSystem, action: Action);