Skip to content

Commit c9d5b5c

Browse files
author
Naseschwarz
committed
Open diff from correct commit
1 parent 3080248 commit c9d5b5c

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

src/popups/file_revlog.rs

+29-32
Original file line numberDiff line numberDiff line change
@@ -157,33 +157,29 @@ impl FileRevlogPopup {
157157

158158
pub fn update_diff(&mut self) -> Result<()> {
159159
if self.is_visible() {
160-
if let Some(commit_id) = self.selected_commit() {
161-
if let Some(open_request) = &self.open_request {
162-
let diff_params = DiffParams {
163-
path: open_request.file_path.clone(),
164-
diff_type: DiffType::Commit(commit_id),
165-
options: self.options.borrow().diff_options(),
166-
};
167-
168-
if let Some((params, last)) =
169-
self.git_diff.last()?
170-
{
171-
if params == diff_params {
172-
self.diff.update(
173-
open_request.file_path.to_string(),
174-
false,
175-
last,
176-
);
177-
178-
return Ok(());
179-
}
160+
if let Some(item) = self.selected_item() {
161+
let diff_params = DiffParams {
162+
path: item.file_path.clone(),
163+
diff_type: DiffType::Commit(item.commit),
164+
options: self.options.borrow().diff_options(),
165+
};
166+
167+
if let Some((params, last)) = self.git_diff.last()? {
168+
if params == diff_params {
169+
self.diff.update(
170+
item.file_path.clone(),
171+
false,
172+
last,
173+
);
174+
175+
return Ok(());
180176
}
177+
}
181178

182-
self.git_diff.request(diff_params)?;
183-
self.diff.clear(true);
179+
self.git_diff.request(diff_params)?;
180+
self.diff.clear(true);
184181

185-
return Ok(());
186-
}
182+
return Ok(());
187183
}
188184

189185
self.diff.clear(false);
@@ -218,19 +214,20 @@ impl FileRevlogPopup {
218214
Ok(())
219215
}
220216

221-
fn selected_commit(&self) -> Option<CommitId> {
217+
fn selected_item(&self) -> Option<&FileHistoryEntry> {
222218
let table_state = self.table_state.take();
223219

224-
let commit_id = table_state.selected().and_then(|selected| {
225-
self.items
226-
.get(selected)
227-
.as_ref()
228-
.map(|entry| entry.commit)
229-
});
220+
let item = table_state
221+
.selected()
222+
.and_then(|selected| self.items.get(selected));
230223

231224
self.table_state.set(table_state);
232225

233-
commit_id
226+
item
227+
}
228+
229+
fn selected_commit(&self) -> Option<CommitId> {
230+
Some(self.selected_item()?.commit)
234231
}
235232

236233
fn can_focus_diff(&self) -> bool {

0 commit comments

Comments
 (0)