Better serialize the git panel (#34622)
Follow-up of https://github.com/zed-industries/zed/pull/29874 Closes https://github.com/zed-industries/zed/issues/34618 Closes https://github.com/zed-industries/zed/issues/34611 Release Notes: - N/A
This commit is contained in:
parent
ceab139f54
commit
5b97cd1900
1 changed files with 38 additions and 27 deletions
|
@ -65,6 +65,7 @@ use ui::{
|
||||||
ScrollbarState, SplitButton, Tooltip, prelude::*,
|
ScrollbarState, SplitButton, Tooltip, prelude::*,
|
||||||
};
|
};
|
||||||
use util::{ResultExt, TryFutureExt, maybe};
|
use util::{ResultExt, TryFutureExt, maybe};
|
||||||
|
use workspace::SERIALIZATION_THROTTLE_TIME;
|
||||||
|
|
||||||
use workspace::{
|
use workspace::{
|
||||||
Workspace,
|
Workspace,
|
||||||
|
@ -342,7 +343,7 @@ pub struct GitPanel {
|
||||||
pending_commit: Option<Task<()>>,
|
pending_commit: Option<Task<()>>,
|
||||||
amend_pending: bool,
|
amend_pending: bool,
|
||||||
signoff_enabled: bool,
|
signoff_enabled: bool,
|
||||||
pending_serialization: Task<Option<()>>,
|
pending_serialization: Task<()>,
|
||||||
pub(crate) project: Entity<Project>,
|
pub(crate) project: Entity<Project>,
|
||||||
scroll_handle: UniformListScrollHandle,
|
scroll_handle: UniformListScrollHandle,
|
||||||
max_width_item_index: Option<usize>,
|
max_width_item_index: Option<usize>,
|
||||||
|
@ -518,7 +519,7 @@ impl GitPanel {
|
||||||
pending_commit: None,
|
pending_commit: None,
|
||||||
amend_pending: false,
|
amend_pending: false,
|
||||||
signoff_enabled: false,
|
signoff_enabled: false,
|
||||||
pending_serialization: Task::ready(None),
|
pending_serialization: Task::ready(()),
|
||||||
single_staged_entry: None,
|
single_staged_entry: None,
|
||||||
single_tracked_entry: None,
|
single_tracked_entry: None,
|
||||||
project,
|
project,
|
||||||
|
@ -709,31 +710,41 @@ impl GitPanel {
|
||||||
let amend_pending = self.amend_pending;
|
let amend_pending = self.amend_pending;
|
||||||
let signoff_enabled = self.signoff_enabled;
|
let signoff_enabled = self.signoff_enabled;
|
||||||
|
|
||||||
let Some(serialization_key) = self
|
self.pending_serialization = cx.spawn(async move |git_panel, cx| {
|
||||||
.workspace
|
cx.background_executor()
|
||||||
.read_with(cx, |workspace, _| Self::serialization_key(workspace))
|
.timer(SERIALIZATION_THROTTLE_TIME)
|
||||||
.ok()
|
.await;
|
||||||
.flatten()
|
let Some(serialization_key) = git_panel
|
||||||
else {
|
.update(cx, |git_panel, cx| {
|
||||||
return;
|
git_panel
|
||||||
};
|
.workspace
|
||||||
|
.read_with(cx, |workspace, _| Self::serialization_key(workspace))
|
||||||
self.pending_serialization = cx.background_spawn(
|
.ok()
|
||||||
async move {
|
.flatten()
|
||||||
KEY_VALUE_STORE
|
})
|
||||||
.write_kvp(
|
.ok()
|
||||||
serialization_key,
|
.flatten()
|
||||||
serde_json::to_string(&SerializedGitPanel {
|
else {
|
||||||
width,
|
return;
|
||||||
amend_pending,
|
};
|
||||||
signoff_enabled,
|
cx.background_spawn(
|
||||||
})?,
|
async move {
|
||||||
)
|
KEY_VALUE_STORE
|
||||||
.await?;
|
.write_kvp(
|
||||||
anyhow::Ok(())
|
serialization_key,
|
||||||
}
|
serde_json::to_string(&SerializedGitPanel {
|
||||||
.log_err(),
|
width,
|
||||||
);
|
amend_pending,
|
||||||
|
signoff_enabled,
|
||||||
|
})?,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
anyhow::Ok(())
|
||||||
|
}
|
||||||
|
.log_err(),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_modal_open(&mut self, open: bool, cx: &mut Context<Self>) {
|
pub(crate) fn set_modal_open(&mut self, open: bool, cx: &mut Context<Self>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue