From 4cd81be05971e5628b954c7d0070ce8a07670b2a Mon Sep 17 00:00:00 2001 From: Leonardo <83844690+LeonardoLarranaga@users.noreply.github.com> Date: Mon, 18 Nov 2024 08:07:47 -0800 Subject: [PATCH] Deleting a file in the Workspace UI now closes the tab (#1937) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Leonardo LarraƱaga --- .../OutlineView/ProjectNavigatorMenuActions.swift | 11 +++++++++++ .../OutlineView/ProjectNavigatorOutlineView.swift | 2 ++ .../OutlineView/ProjectNavigatorViewController.swift | 1 + 3 files changed, 14 insertions(+) diff --git a/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorMenuActions.swift b/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorMenuActions.swift index 9ab9d3ed2..8f469e329 100644 --- a/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorMenuActions.swift +++ b/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorMenuActions.swift @@ -6,6 +6,7 @@ // import AppKit +import SwiftUI extension ProjectNavigatorMenu { /// - Returns: the currently selected `CEWorkspaceFile` items in the outline view. @@ -150,6 +151,9 @@ extension ProjectNavigatorMenu { func trash() { selectedItems().forEach { item in workspace?.workspaceFileManager?.trash(file: item) + withAnimation { + sender.editor?.closeTab(file: item) + } } reloadData() } @@ -165,6 +169,13 @@ extension ProjectNavigatorMenu { } else { workspace?.workspaceFileManager?.batchDelete(files: selectedItems) } + + withAnimation { + selectedItems.forEach { item in + sender.editor?.closeTab(file: item) + } + } + reloadData() } diff --git a/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorOutlineView.swift b/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorOutlineView.swift index cb9456663..5b97d09b2 100644 --- a/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorOutlineView.swift +++ b/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorOutlineView.swift @@ -12,6 +12,7 @@ import Combine struct ProjectNavigatorOutlineView: NSViewControllerRepresentable { @EnvironmentObject var workspace: WorkspaceDocument + @EnvironmentObject var editorManager: EditorManager @StateObject var prefs: Settings = .shared @@ -21,6 +22,7 @@ struct ProjectNavigatorOutlineView: NSViewControllerRepresentable { let controller = ProjectNavigatorViewController() controller.workspace = workspace controller.iconColor = prefs.preferences.general.fileIconStyle + controller.editor = editorManager.activeEditor workspace.workspaceFileManager?.addObserver(context.coordinator) context.coordinator.controller = controller diff --git a/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorViewController.swift b/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorViewController.swift index 8851fd1ec..f76f07efc 100644 --- a/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorViewController.swift +++ b/CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorViewController.swift @@ -36,6 +36,7 @@ final class ProjectNavigatorViewController: NSViewController { var expandedItems: Set = [] weak var workspace: WorkspaceDocument? + weak var editor: Editor? var iconColor: SettingsData.FileIconStyle = .color { willSet {