Files
coop/crates/ui/src/input/change.rs
reya 61cad5dd96 chore: refactor the input component (#165)
* refactor the input component

* fix clippy

* clean up
2025-09-25 08:03:14 +07:00

41 lines
894 B
Rust

use std::fmt::Debug;
use crate::history::HistoryItem;
use crate::input::cursor::Selection;
#[derive(Debug, PartialEq, Clone)]
pub struct Change {
pub(crate) old_range: Selection,
pub(crate) old_text: String,
pub(crate) new_range: Selection,
pub(crate) new_text: String,
version: usize,
}
impl Change {
pub fn new(
old_range: impl Into<Selection>,
old_text: &str,
new_range: impl Into<Selection>,
new_text: &str,
) -> Self {
Self {
old_range: old_range.into(),
old_text: old_text.to_string(),
new_range: new_range.into(),
new_text: new_text.to_string(),
version: 0,
}
}
}
impl HistoryItem for Change {
fn version(&self) -> usize {
self.version
}
fn set_version(&mut self, version: usize) {
self.version = version;
}
}