Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/desktop/src/plugin_host/native/custom_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ pub fn version(app: &App, id: u64) -> u64 {
if let Some(e) = store.entries.get(&id) {
(
e.stamp,
e.diffs.keys_rev(),
e.diffs.rev(),
e.diffs.mode() == DiffMode::Split,
e.diffs.expand_mode() == ExpandMode::Expand,
e.diffs.only(),
Expand All @@ -249,6 +251,8 @@ pub fn watched_stamp(app: &App) -> u64 {
(
*id,
e.stamp,
e.diffs.keys_rev(),
e.diffs.rev(),
e.diffs.mode() == DiffMode::Split,
e.diffs.expand_mode() == ExpandMode::Expand,
e.diffs.only(),
Expand Down
40 changes: 30 additions & 10 deletions apps/desktop/src/plugin_host/native/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,22 +453,42 @@ pub fn tree_version(app: &App, session: &str) -> u64 {
}

pub type FindVersion = (usize, usize, String, bool);
pub type DiffVersion = (u64, bool, bool, Option<usize>, Option<FindVersion>);
pub type DiffVersion = (u64, u64, u64, bool, bool, Option<usize>, Option<FindVersion>);

/// The version of what `Dep::Diff(session)` reads, the file heading stuck over the scrolled
/// diff included: scrolling past a file's heading sticks it without changing the diff.
/// The version of what `Dep::Diff(session)` reads: the session stamp (kept at `.0` for
/// `Diff.Changed`), `diffs.keys_rev()` / `diffs.rev()` (bumped when header collapse, fold
/// reveal, wrap toggle, or offline text failure rebuilds rows without touching `sr.stamp`),
/// the active modes, sticky header, and find bar.
pub fn version(app: &App, session: &str) -> DiffVersion {
let sr = app.kernel.slots.get(&crate::review::REVIEW).sessions.get(session);
let review = app.kernel.slots.get(&crate::review::REVIEW);
let sr = review.sessions.get(session);
// The find bar the diff draws over itself: open, its matches, its field.
let find = sr.map(|sr| &sr.diffs).filter(|d| d.find_open()).map(|d| (d.find_count(), d.find_index(), d.find.input.text.clone(), d.find.input.focused));
(sr.map_or(0, |sr| sr.stamp), app.kernel.slots.get(&crate::review::REVIEW).diff_mode == DiffMode::Split, app.kernel.slots.get(&crate::review::REVIEW).expand_mode == ExpandMode::Expand, sr.and_then(|sr| sr.diffs.sticky()), find)
(
sr.map_or(0, |sr| sr.stamp),
sr.map_or(0, |sr| sr.diffs.keys_rev()),
sr.map_or(0, |sr| sr.diffs.rev()),
review.diff_mode == DiffMode::Split,
review.expand_mode == ExpandMode::Expand,
sr.and_then(|sr| sr.diffs.sticky()),
find,
)
}

/// The version of what `Dep::NarrowReview(session)` reads: the files open in the narrow list
/// and the session's line comments.
pub fn narrow_version(app: &App, session: &str) -> (Vec<String>, u64) {
let open = app.kernel.slots.get(&crate::review::REVIEW).sessions.get(session).map(|sr| sr.narrow.open_paths()).unwrap_or_default();
(open, app.kernel.slots.get(&crate::line_comments::LINE_COMMENTS).version(session))
/// The version of what `Dep::NarrowReview(session)` reads: the session stamp, each open
/// narrow diff's path and row/wrap revisions, and the session's line comments.
pub fn narrow_version(app: &App, session: &str) -> u64 {
use std::hash::{Hash, Hasher};
let mut h = std::hash::DefaultHasher::new();
if let Some(sr) = app.kernel.slots.get(&crate::review::REVIEW).sessions.get(session) {
sr.stamp.hash(&mut h);
sr.narrow.open_diffs().len().hash(&mut h);
for (path, doc) in sr.narrow.open_diffs() {
(path, doc.keys_rev(), doc.rev()).hash(&mut h);
}
}
app.kernel.slots.get(&crate::line_comments::LINE_COMMENTS).version(session).hash(&mut h);
h.finish()
}

/// `ui.diffView`: the preview of `file`, else every file one under another; with `list`, the
Expand Down
8 changes: 5 additions & 3 deletions crates/opencode-code-view/src/diff/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ impl<S: 'static> Inner<S> {
}
};
let after = st.selection();
let path = st.files()[f].path().to_owned();
if let Some(notes) = &notes {
let path = notes.as_ref().and_then(|_| st.files().get(f).map(|file| file.path().to_owned()));
if let (Some(notes), Some(path)) = (&notes, path) {
hand_off(notes.as_ref(), s, &path, before, after, ended.then_some(unselect), tx);
}
})
Expand Down Expand Up @@ -411,7 +411,9 @@ impl<S: 'static> Inner<S> {
let before = st.selection();
st.click_code(f, at);
let after = st.selection();
let path = st.files()[f].path().to_owned();
let Some(path) = st.files().get(f).map(|file| file.path().to_owned()) else {
return;
};
hand_off(notes.as_ref(), s, &path, before, after, Some(None), tx);
});
}
Expand Down
7 changes: 6 additions & 1 deletion crates/opencode-code-view/src/diff/nav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ impl DiffDocState {
}

pub fn scroll_to_file(&mut self, file: usize, tx: &mut Tx) {
let Some(&r) = self.file_rows.get(file) else { return };
if self.only.is_some_and(|o| o != file) {
return;
}
let Some(&r) = self.file_rows.get(file).filter(|&&r| (r as usize) < self.rows.len()) else {
return;
};
tx.instant();
self.reveal_at_top(r, tx);
self.visible = file;
Expand Down
21 changes: 18 additions & 3 deletions crates/opencode-code-view/src/diff/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ impl DiffDocState {
&self.files
}

pub fn rev(&self) -> u64 {
self.rev
}

pub fn keys_rev(&self) -> u64 {
self.keys_rev
}

/// The rows' height one under another, unwrapped: a diff shown whole inside another scroll.
/// A row laid out with comments under it counts as tall as it came out.
pub fn rows_height(&self) -> f32 {
Expand Down Expand Up @@ -565,11 +573,13 @@ impl DiffDocState {

pub(crate) fn set_visible_rows(&mut self, rows: Range<usize>) -> (Option<usize>, bool) {
let before_sticky = self.sticky();
self.visible_rows = rows;
let len = self.rows.len();
self.visible_rows = rows.start.min(len)..rows.end.min(len);
if let Some(n) = self.nav
&& self.visible_rows.contains(&(n as usize))
&& let Some(&r) = self.rows.get(n as usize)
{
self.visible = self.rows[n as usize].file();
self.visible = r.file();
} else {
self.nav = None;
if let Some(&r) = self.rows.get(self.visible_rows.start) {
Expand Down Expand Up @@ -605,8 +615,11 @@ impl DiffDocState {
return None;
}
let f = self.visible;
if self.collapsed(f) || self.only.is_some_and(|o| o != f) {
return None;
}
let header = *self.file_rows.get(f)? as usize;
(self.visible_rows.start > header).then_some(f)
(self.visible_rows.start > header && self.visible_rows.start < self.rows.len()).then_some(f)
}

/// Row `r`'s height: as laid out, else its kind's (a wrapped line, or one with comments
Expand Down Expand Up @@ -746,7 +759,9 @@ impl DiffDocState {
}
}
}
let len = rows.len();
self.rows = rows;
self.visible_rows = self.visible_rows.start.min(len)..self.visible_rows.end.min(len);
self.refind();
}

Expand Down
11 changes: 8 additions & 3 deletions crates/opencode-code-view/src/diff/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ impl<S: 'static> DiffViewer<S> {
}

fn row_keys<S: 'static>(get: Get<S>) -> impl for<'a> Fn(&'a S, usize) -> Cow<'a, str> + 'static {
move |s, i| Cow::Borrowed(get(s).keys[i].as_str())
move |s, i| match get(s).keys.get(i) {
Some(k) => Cow::Borrowed(k.as_str()),
None => Cow::Owned(format!("df-stale-{i}")),
}
}

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -367,8 +370,10 @@ fn annotation_wrap(pal: &Pal, st: &DiffDocState, f: usize, gutter: f32, line: El
impl<S: 'static> Inner<S> {
fn row(&self, s: &S, i: usize) -> El {
let st = (self.d.get)(s);
let r = st.rows[i];
let key = st.keys[i].as_str();
let (Some(&r), Some(key)) = (st.rows.get(i), st.keys.get(i)) else {
return el();
};
let key = key.as_str();
match r {
DiffRow::File(f) if self.d.header_actions.is_none() => {
let fu = f as usize;
Expand Down
4 changes: 4 additions & 0 deletions features/review/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ impl NarrowReview {
self.open.iter().map(|(p, _)| p.clone()).collect()
}

pub fn open_diffs(&self) -> &[(String, DiffDocState)] {
&self.open
}

pub fn is_open(&self, path: &str) -> bool {
self.open.iter().any(|(p, _)| p == path)
}
Expand Down
Loading