Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-vcs/src/diff.rs')
-rw-r--r--helix-vcs/src/diff.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/helix-vcs/src/diff.rs b/helix-vcs/src/diff.rs
index 6ec29813..cc97ef85 100644
--- a/helix-vcs/src/diff.rs
+++ b/helix-vcs/src/diff.rs
@@ -35,6 +35,7 @@ struct DiffInner {
hunks: Vec<Hunk>,
}
+/// Representation of a diff that can be updated.
#[derive(Clone, Debug)]
pub struct DiffHandle {
channel: UnboundedSender<Event>,
@@ -65,10 +66,12 @@ impl DiffHandle {
(differ, handle)
}
+ /// Switch base and modified texts' roles
pub fn invert(&mut self) {
self.inverted = !self.inverted;
}
+ /// Load the actual diff
pub fn load(&self) -> Diff {
Diff {
diff: self.diff.read(),
@@ -89,6 +92,7 @@ impl DiffHandle {
self.update_document_impl(doc, self.inverted, Some(RenderLock { lock, timeout }))
}
+ /// Updates the base text of the diff. Returns if the update was successful.
pub fn update_diff_base(&self, diff_base: Rope) -> bool {
self.update_document_impl(diff_base, !self.inverted, None)
}
@@ -128,6 +132,7 @@ pub struct Diff<'a> {
}
impl Diff<'_> {
+ /// Returns the base [Rope] of the [Diff]
pub fn diff_base(&self) -> &Rope {
if self.inverted {
&self.diff.doc
@@ -136,6 +141,7 @@ impl Diff<'_> {
}
}
+ /// Returns the [Rope] being compared against
pub fn doc(&self) -> &Rope {
if self.inverted {
&self.diff.diff_base
@@ -166,6 +172,7 @@ impl Diff<'_> {
self.len() == 0
}
+ /// Gives the index of the first hunk after the given line, if one exists.
pub fn next_hunk(&self, line: u32) -> Option<u32> {
let hunk_range = if self.inverted {
|hunk: &Hunk| hunk.before.clone()
@@ -192,6 +199,7 @@ impl Diff<'_> {
}
}
+ /// Gives the index of the first hunk before the given line, if one exists.
pub fn prev_hunk(&self, line: u32) -> Option<u32> {
let hunk_range = if self.inverted {
|hunk: &Hunk| hunk.before.clone()
@@ -235,6 +243,7 @@ impl Diff<'_> {
}
}
+ /// Returns the index of the hunk containing the given line if it exists.
pub fn hunk_at(&self, line: u32, include_removal: bool) -> Option<u32> {
let hunk_range = if self.inverted {
|hunk: &Hunk| hunk.before.clone()