editor: Add revert file action to command palette (#16012)

Release Notes:

- Added an `editor::RevertFile` action
This commit is contained in:
CharlesChen0823 2024-08-13 19:44:41 +08:00 committed by GitHub
parent ab98f16280
commit fe190359d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 29 deletions

View file

@ -24,8 +24,8 @@ use crate::{
hunk_status, hunks_for_selections,
mouse_context_menu::MouseContextMenu,
BlockDisposition, BlockProperties, BlockStyle, CustomBlockId, DiffRowHighlight, Editor,
EditorElement, EditorSnapshot, ExpandAllHunkDiffs, RangeToAnchorExt, RevertSelectedHunks,
ToDisplayPoint, ToggleHunkDiff,
EditorElement, EditorSnapshot, ExpandAllHunkDiffs, RangeToAnchorExt, RevertFile,
RevertSelectedHunks, ToDisplayPoint, ToggleHunkDiff,
};
#[derive(Debug, Clone)]
@ -139,33 +139,7 @@ impl Editor {
}
}
})
.entry("Revert File", None, {
let editor = editor_handle.clone();
move |cx| {
let mut revert_changes = HashMap::default();
let multi_buffer = editor.read(cx).buffer().clone();
let multi_buffer_snapshot = multi_buffer.read(cx).snapshot(cx);
for hunk in crate::hunks_for_rows(
Some(MultiBufferRow(0)..multi_buffer_snapshot.max_buffer_row())
.into_iter(),
&multi_buffer_snapshot,
) {
Editor::prepare_revert_change(
&mut revert_changes,
&multi_buffer,
&hunk,
cx,
);
}
if !revert_changes.is_empty() {
editor.update(cx, |editor, cx| {
editor.transact(cx, |editor, cx| {
editor.revert(revert_changes, cx);
});
});
}
}
})
.action("Revert File", RevertFile.boxed_clone())
}),
cx,
)