Skip to content

Fix: Navigator Loses Editing, Drawer Not Draggable #2062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ extension CEWorkspaceFileManager {
@discardableResult
public func move(file: CEWorkspaceFile, to newLocation: URL) throws -> CEWorkspaceFile? {
do {
guard fileManager.fileExists(atPath: file.url.path()) else {
guard fileManager.fileExists(atPath: file.url.path(percentEncoded: false)) else {
throw FileManagerError.originFileNotFound
}

guard !fileManager.fileExists(atPath: newLocation.path) else {
guard !fileManager.fileExists(atPath: newLocation.path(percentEncoded: false)) else {
throw FileManagerError.destinationFileExists
}

Expand Down Expand Up @@ -305,7 +305,9 @@ extension CEWorkspaceFileManager {
/// - newLocation: The location to copy to.
public func copy(file: CEWorkspaceFile, to newLocation: URL) throws {
do {
guard file.url != newLocation && !fileManager.fileExists(atPath: newLocation.absoluteString) else {
guard file.url != newLocation && !fileManager.fileExists(
atPath: newLocation.absoluteURL.path(percentEncoded: false)
) else {
throw FileManagerError.originFileNotFound
}
try fileManager.copyItem(at: file.url, to: newLocation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,16 @@ struct ProjectNavigatorOutlineView: NSViewControllerRepresentable {
guard let outlineView = controller?.outlineView else { return }
let selectedRows = outlineView.selectedRowIndexes.compactMap({ outlineView.item(atRow: $0) })

for item in updatedItems {
outlineView.reloadItem(item, reloadChildren: true)
// If some text view inside the outline view is first responder right now, push the update off
// until editing is finished using the `shouldReloadAfterDoneEditing` flag.
if outlineView.window?.firstResponder !== outlineView
&& outlineView.window?.firstResponder is NSTextView
&& (outlineView.window?.firstResponder as? NSView)?.isDescendant(of: outlineView) == true {
controller?.shouldReloadAfterDoneEditing = true
} else {
for item in updatedItems {
outlineView.reloadItem(item, reloadChildren: true)
}
}

// Restore selected items where the files still exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
protocol OutlineTableViewCellDelegate: AnyObject {
func moveFile(file: CEWorkspaceFile, to destination: URL)
func copyFile(file: CEWorkspaceFile, to destination: URL)
func cellDidFinishEditing()
}

/// A `NSTableCellView` showing an ``icon`` and a ``label``
Expand Down Expand Up @@ -64,5 +65,6 @@ final class ProjectNavigatorTableViewCell: FileSystemTableViewCell {
} else {
textField?.stringValue = fileItem.labelFileName()
}
delegate?.cellDidFinishEditing()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ extension ProjectNavigatorViewController: OutlineTableViewCellDelegate {
alert.runModal()
}
}

func cellDidFinishEditing() {
guard shouldReloadAfterDoneEditing else { return }
outlineView.reloadData()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ final class ProjectNavigatorViewController: NSViewController {
/// to open the file a second time.
var shouldSendSelectionUpdate: Bool = true

var shouldReloadAfterDoneEditing: Bool = false

var filterIsEmpty: Bool {
workspace?.navigatorFilter.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct SplitViewControllerView: NSViewControllerRepresentable {
@Binding var viewController: () -> SplitViewController?

func makeNSViewController(context: Context) -> SplitViewController {
let controller = SplitViewController(axis: axis) { controller in
let controller = SplitViewController(axis: axis, parentView: self) { controller in
updateItems(controller: controller)
}
return controller
Expand Down Expand Up @@ -64,10 +64,6 @@ struct SplitViewControllerView: NSViewControllerRepresentable {
}
}
}

func makeCoordinator() -> SplitViewController {
SplitViewController(axis: axis, setUpItems: nil)
}
}

final class SplitViewController: NSSplitViewController {
Expand Down Expand Up @@ -108,8 +104,9 @@ final class SplitViewController: NSSplitViewController {

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

init(axis: Axis, setUpItems: ((SplitViewController) -> Void)?) {
init(axis: Axis, parentView: SplitViewControllerView?, setUpItems: ((SplitViewController) -> Void)?) {
self.axis = axis
self.parentView = parentView
self.setUpItems = setUpItems
super.init(nibName: nil, bundle: nil)
}
Expand Down