B:BD[
3.26390] → [
5.4022:4246]
app::Msg::Cursor(msg) => cursor::update(
&mut state.cursor,
&mut state.files,
state.repo.as_ref(),
msg,
)
.map(|msg| Msg::View(app::Msg::ToRepo(msg))),
app::Msg::Cursor(msg) => {
let cursor_task = cursor::update(
&mut state.cursor,
&mut state.files,
state.repo.as_ref(),
msg,
)
.map(|msg| Msg::View(app::Msg::ToRepo(msg)));
// If the selected file's diff is already loaded, scroll back to its
// last offset
let scroll_task = match state.cursor.selection.as_ref() {
Some(cursor::Selection::UntrackedFile { ix: _, path }) => {
let id = file::Id {
path: path.clone(),
file_kind: file::Kind::Untracked,
};
if let Some(nav) = state
.files_diffs
.get(&id)
.and_then(|state| state.nav.as_ref())
{
task::scroll_to(
nav.id.clone(),
scrollable::AbsoluteOffset {
x: 0.0,
y: nav.offset,
},
)
} else {
Task::none()
}
}
Some(cursor::Selection::ChangedFile { ix: _, path }) => {
let id = file::Id {
path: path.clone(),
file_kind: file::Kind::Changed,
};
if let Some(nav) = state
.files_diffs
.get(&id)
.and_then(|state| state.nav.as_ref())
{
task::scroll_to(
nav.id.clone(),
scrollable::AbsoluteOffset {
x: 0.0,
y: nav.offset,
},
)
} else {
Task::none()
}
}
Some(cursor::Selection::LogChange {
ix: _,
hash,
message: _,
file: Some(cursor::LogChangeFileSelection { ix: _, path }),
}) => {
let id = repo::LogFileId {
hash: *hash,
path: path.clone(),
};
if let Some(nav) = state
.log_diffs
.get(&id)
.and_then(|diff| diff.state.nav.as_ref())
{
task::scroll_to(
nav.id.clone(),
scrollable::AbsoluteOffset {
x: 0.0,
y: nav.offset,
},
)
} else {
Task::none()
}
}
Some(cursor::Selection::LogChange {
ix: _,
hash: _,
message: _,
file: None,
})
| None => Task::none(),
};
Task::batch([cursor_task, scroll_task])
}