pub struct TextChange {
pub start_idx: u32,
pub end_idx: u32,
pub content: String,
}
Expand description
An editor-friendly representation of a text change in a given buffer.
It’s expressed with a range of characters and a string of content that should replace them, allowing representation of any combination of deletions, insertions or replacements.
Bulky and large operations will result in a single TextChange
effectively sending the whole
new buffer, but smaller changes are efficient and easy to create or apply.
§Examples
To insert ‘a’ after 4th character we should send:
codemp::api::TextChange { start_idx: 4, end_idx: 4, content: "a".into() };
To delete the fourth character we should send:
codemp::api::TextChange { start_idx: 3, end_idx: 4, content: "".into() };
let change = codemp::api::TextChange {
start_idx: 6,
end_idx: 11,
content: "mom".to_string()
};
let before = "hello world!";
let after = change.apply(before);
assert_eq!(after, "hello mom!");
Fields§
§start_idx: u32
Range start of text change, as char indexes in buffer previous state.
end_idx: u32
Range end of text change, as char indexes in buffer previous state.
content: String
New content of text inside span.
Implementations§
Source§impl TextChange
impl TextChange
Sourcepub fn span(&self) -> Range<usize>
pub fn span(&self) -> Range<usize>
Returns the std::ops::Range
representing this change’s span.
Source§impl TextChange
impl TextChange
Sourcepub fn is_delete(&self) -> bool
pub fn is_delete(&self) -> bool
Returns true if this TextChange
deletes existing text.
Note that this is is not mutually exclusive with TextChange::is_insert.
Sourcepub fn is_insert(&self) -> bool
pub fn is_insert(&self) -> bool
Returns true if this TextChange
adds new text.
Note that this is is not mutually exclusive with TextChange::is_delete.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this TextChange
is effectively as no-op.
Trait Implementations§
Source§impl AsyncSender<TextChange> for BufferController
impl AsyncSender<TextChange> for BufferController
Source§fn send(&self, op: TextChange) -> ControllerResult<()>
fn send(&self, op: TextChange) -> ControllerResult<()>
Source§impl Clone for TextChange
impl Clone for TextChange
Source§fn clone(&self) -> TextChange
fn clone(&self) -> TextChange
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TextChange
impl Debug for TextChange
Source§impl Default for TextChange
impl Default for TextChange
Source§fn default() -> TextChange
fn default() -> TextChange
Source§impl<'de> Deserialize<'de> for TextChange
impl<'de> Deserialize<'de> for TextChange
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for TextChange
impl Serialize for TextChange
impl Controller<TextChange, BufferUpdate> for BufferController
Auto Trait Implementations§
impl Freeze for TextChange
impl RefUnwindSafe for TextChange
impl Send for TextChange
impl Sync for TextChange
impl Unpin for TextChange
impl UnwindSafe for TextChange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request