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
|
@ -1762,6 +1762,23 @@ impl MultiBuffer {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
/// Preserve preview tabs containing this multibuffer until additional edits occur.
|
||||
pub fn refresh_preview(&self, cx: &mut ModelContext<Self>) {
|
||||
for buffer_state in self.buffers.borrow().values() {
|
||||
buffer_state
|
||||
.buffer
|
||||
.update(cx, |buffer, _cx| buffer.refresh_preview());
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether we should preserve the preview status of a tab containing this multi-buffer.
|
||||
pub fn preserve_preview(&self, cx: &AppContext) -> bool {
|
||||
self.buffers
|
||||
.borrow()
|
||||
.values()
|
||||
.all(|state| state.buffer.read(cx).preserve_preview())
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn is_parsing(&self, cx: &AppContext) -> bool {
|
||||
self.as_singleton().unwrap().read(cx).is_parsing()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue