Skip to content

Commit 8867f3f

Browse files
Fix: Navigator Loses Editing, Drawer Not Draggable (#2062)
Fix: Navigator Losing Editing, Drawer Not Draggable, Rename Fails With Spaces
1 parent 21427bf commit 8867f3f

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFileManager+FileManagement.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ extension CEWorkspaceFileManager {
252252
@discardableResult
253253
public func move(file: CEWorkspaceFile, to newLocation: URL) throws -> CEWorkspaceFile? {
254254
do {
255-
guard fileManager.fileExists(atPath: file.url.path()) else {
255+
guard fileManager.fileExists(atPath: file.url.path(percentEncoded: false)) else {
256256
throw FileManagerError.originFileNotFound
257257
}
258258

259-
guard !fileManager.fileExists(atPath: newLocation.path) else {
259+
guard !fileManager.fileExists(atPath: newLocation.path(percentEncoded: false)) else {
260260
throw FileManagerError.destinationFileExists
261261
}
262262

@@ -306,7 +306,9 @@ extension CEWorkspaceFileManager {
306306
/// - newLocation: The location to copy to.
307307
public func copy(file: CEWorkspaceFile, to newLocation: URL) throws {
308308
do {
309-
guard file.url != newLocation && !fileManager.fileExists(atPath: newLocation.absoluteString) else {
309+
guard file.url != newLocation && !fileManager.fileExists(
310+
atPath: newLocation.absoluteURL.path(percentEncoded: false)
311+
) else {
310312
throw FileManagerError.originFileNotFound
311313
}
312314
try fileManager.copyItem(at: file.url, to: newLocation)

CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorOutlineView.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,16 @@ struct ProjectNavigatorOutlineView: NSViewControllerRepresentable {
8585
guard let outlineView = controller?.outlineView else { return }
8686
let selectedRows = outlineView.selectedRowIndexes.compactMap({ outlineView.item(atRow: $0) })
8787

88-
for item in updatedItems {
89-
outlineView.reloadItem(item, reloadChildren: true)
88+
// If some text view inside the outline view is first responder right now, push the update off
89+
// until editing is finished using the `shouldReloadAfterDoneEditing` flag.
90+
if outlineView.window?.firstResponder !== outlineView
91+
&& outlineView.window?.firstResponder is NSTextView
92+
&& (outlineView.window?.firstResponder as? NSView)?.isDescendant(of: outlineView) == true {
93+
controller?.shouldReloadAfterDoneEditing = true
94+
} else {
95+
for item in updatedItems {
96+
outlineView.reloadItem(item, reloadChildren: true)
97+
}
9098
}
9199

92100
// Restore selected items where the files still exist.

CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorTableViewCell.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SwiftUI
1010
protocol OutlineTableViewCellDelegate: AnyObject {
1111
func moveFile(file: CEWorkspaceFile, to destination: URL)
1212
func copyFile(file: CEWorkspaceFile, to destination: URL)
13+
func cellDidFinishEditing()
1314
}
1415

1516
/// A `NSTableCellView` showing an ``icon`` and a ``label``
@@ -64,5 +65,6 @@ final class ProjectNavigatorTableViewCell: FileSystemTableViewCell {
6465
} else {
6566
textField?.stringValue = fileItem.labelFileName()
6667
}
68+
delegate?.cellDidFinishEditing()
6769
}
6870
}

CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorViewController+OutlineTableViewCellDelegate.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ extension ProjectNavigatorViewController: OutlineTableViewCellDelegate {
3939
alert.runModal()
4040
}
4141
}
42+
43+
func cellDidFinishEditing() {
44+
guard shouldReloadAfterDoneEditing else { return }
45+
outlineView.reloadData()
46+
}
4247
}

CodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ final class ProjectNavigatorViewController: NSViewController {
6464
/// to open the file a second time.
6565
var shouldSendSelectionUpdate: Bool = true
6666

67+
var shouldReloadAfterDoneEditing: Bool = false
68+
6769
var filterIsEmpty: Bool {
6870
workspace?.navigatorFilter.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == true
6971
}

CodeEdit/Features/SplitView/Views/SplitViewControllerView.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct SplitViewControllerView: NSViewControllerRepresentable {
1515
@Binding var viewController: () -> SplitViewController?
1616

1717
func makeNSViewController(context: Context) -> SplitViewController {
18-
let controller = SplitViewController(axis: axis) { controller in
18+
let controller = SplitViewController(axis: axis, parentView: self) { controller in
1919
updateItems(controller: controller)
2020
}
2121
return controller
@@ -64,10 +64,6 @@ struct SplitViewControllerView: NSViewControllerRepresentable {
6464
}
6565
}
6666
}
67-
68-
func makeCoordinator() -> SplitViewController {
69-
SplitViewController(axis: axis, setUpItems: nil)
70-
}
7167
}
7268

7369
final class SplitViewController: NSSplitViewController {
@@ -108,8 +104,9 @@ final class SplitViewController: NSSplitViewController {
108104

109105
var setUpItems: ((SplitViewController) -> Void)?
110106

111-
init(axis: Axis, setUpItems: ((SplitViewController) -> Void)?) {
107+
init(axis: Axis, parentView: SplitViewControllerView?, setUpItems: ((SplitViewController) -> Void)?) {
112108
self.axis = axis
109+
self.parentView = parentView
113110
self.setUpItems = setUpItems
114111
super.init(nibName: nil, bundle: nil)
115112
}

0 commit comments

Comments
 (0)