Add clear recent files history command (#42176)

![2025-11-07
181619](https://github.com/user-attachments/assets/a9bef7a6-dc0b-4db2-85e5-2e1df7b21cfa)


Release Notes:

- Added "workspace: clear navigation history" command
This commit is contained in:
Libon
2025-11-11 15:42:00 +02:00
committed by GitHub
parent 58db38722b
commit 9be5e31aca
3 changed files with 128 additions and 0 deletions
+19
View File
@@ -4041,6 +4041,25 @@ impl NavHistory {
self.0.lock().mode = NavigationMode::Normal;
}
pub fn clear(&mut self, cx: &mut App) {
let mut state = self.0.lock();
if state.backward_stack.is_empty()
&& state.forward_stack.is_empty()
&& state.closed_stack.is_empty()
&& state.paths_by_item.is_empty()
{
return;
}
state.mode = NavigationMode::Normal;
state.backward_stack.clear();
state.forward_stack.clear();
state.closed_stack.clear();
state.paths_by_item.clear();
state.did_update(cx);
}
pub fn pop(&mut self, mode: NavigationMode, cx: &mut App) -> Option<NavigationEntry> {
let mut state = self.0.lock();
let entry = match mode {
+13
View File
@@ -199,6 +199,8 @@ actions!(
AddFolderToProject,
/// Clears all notifications.
ClearAllNotifications,
/// Clears all navigation history, including forward/backward navigation, recently opened files, and recently closed tabs. **This action is irreversible**.
ClearNavigationHistory,
/// Closes the active dock.
CloseActiveDock,
/// Closes all docks.
@@ -1917,6 +1919,12 @@ impl Workspace {
.collect()
}
pub fn clear_navigation_history(&mut self, _window: &mut Window, cx: &mut Context<Workspace>) {
for pane in &self.panes {
pane.update(cx, |pane, cx| pane.nav_history_mut().clear(cx));
}
}
fn navigate_history(
&mut self,
pane: WeakEntity<Pane>,
@@ -5858,6 +5866,11 @@ impl Workspace {
workspace.clear_all_notifications(cx);
},
))
.on_action(cx.listener(
|workspace: &mut Workspace, _: &ClearNavigationHistory, window, cx| {
workspace.clear_navigation_history(window, cx);
},
))
.on_action(cx.listener(
|workspace: &mut Workspace, _: &SuppressNotification, _, cx| {
if let Some((notification_id, _)) = workspace.notifications.pop() {