Open workflow step editors as preview tabs (#15928)
This PR opens workflow step editors as preview tabs and closes them upon exiting the step if they are still in preview mode and they weren't already open before entering the step. Making this work was tricky, because we often edit the buffer as part of displaying the workflow step suggestions to create empty lines where we can generate. We undo these edits if the transformation is not applied, but they were causing the preview to be dismissed. After trying a few approaches, I decided to give workspace `Item`s a `preserve_preview` method that defaults to false. When the workspace sees an edit event for the item, it checks if the item wants to preserve its preview. For buffers, after editing, you can call `refresh_preview`, which sets a preview version to the current version of the buffer. Any edits after this version will cause preview to not be preserved. One final issue is with async auto-indent. To ensure these async edits don't dismiss the preview, I automatically refresh the preview version if preview was preserved prior to performing the auto-indent. The assumption is that these are edits created by other edits, and if we didn't want to dismiss the preview with the originating edits, then the auto-indent edits shouldn't dismiss it either. Release Notes: - N/A --------- Co-authored-by: Jason <jason@zed.dev>
This commit is contained in:
parent
a5961c8d45
commit
da8d1306af
11 changed files with 497 additions and 324 deletions
|
@ -97,6 +97,7 @@ pub struct Buffer {
|
|||
/// The version vector when this buffer was last loaded from
|
||||
/// or saved to disk.
|
||||
saved_version: clock::Global,
|
||||
preview_version: clock::Global,
|
||||
transaction_depth: usize,
|
||||
was_dirty_before_starting_transaction: Option<bool>,
|
||||
reload_task: Option<Task<Result<()>>>,
|
||||
|
@ -703,6 +704,7 @@ impl Buffer {
|
|||
Self {
|
||||
saved_mtime,
|
||||
saved_version: buffer.version(),
|
||||
preview_version: buffer.version(),
|
||||
reload_task: None,
|
||||
transaction_depth: 0,
|
||||
was_dirty_before_starting_transaction: None,
|
||||
|
@ -1351,7 +1353,11 @@ impl Buffer {
|
|||
})
|
||||
.collect();
|
||||
|
||||
let preserve_preview = self.preserve_preview();
|
||||
self.edit(edits, None, cx);
|
||||
if preserve_preview {
|
||||
self.refresh_preview();
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a minimal edit that will cause the given row to be indented
|
||||
|
@ -2195,6 +2201,18 @@ impl Buffer {
|
|||
pub fn completion_triggers(&self) -> &[String] {
|
||||
&self.completion_triggers
|
||||
}
|
||||
|
||||
/// Call this directly after performing edits to prevent the preview tab
|
||||
/// from being dismissed by those edits. It causes `should_dismiss_preview`
|
||||
/// to return false until there are additional edits.
|
||||
pub fn refresh_preview(&mut self) {
|
||||
self.preview_version = self.version.clone();
|
||||
}
|
||||
|
||||
/// Whether we should preserve the preview status of a tab containing this buffer.
|
||||
pub fn preserve_preview(&self) -> bool {
|
||||
!self.has_edits_since(&self.preview_version)
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue