Skip to content

Commit

Permalink
Refactor FileNode
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Aug 22, 2024
1 parent 851d41c commit 005a773
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions CotEditor/Sources/FileNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,9 @@ struct FileNode: Equatable {
var isDirectory: Bool { self.kind == .folder }
var isHidden: Bool { self.name.starts(with: ".") }
var isWritable: Bool { self.permissions.user.contains(.write) }
var directoryURL: URL { self.isDirectory ? self.fileURL : self.fileURL.deletingLastPathComponent() }
}


extension FileNode: Hashable {

func hash(into hasher: inout Hasher) {

hasher.combine(self.id)
}
}


extension FileNode: Identifiable {
var directoryURL: URL { self.isDirectory ? self.fileURL : self.fileURL.deletingLastPathComponent() }

var id: [String] { self.paths + [self.name] }
}


extension FileNode {

init?(fileWrapper: FileWrapper, paths: [String] = [], fileURL: URL) {

Expand All @@ -88,7 +71,25 @@ extension FileNode {
.sorted(using: SortDescriptor(\.isDirectory))
}
}
}


extension FileNode: Hashable {

func hash(into hasher: inout Hasher) {

hasher.combine(self.id)
}
}


extension FileNode: Identifiable {

var id: [String] { self.paths + [self.name] }
}


extension FileNode {

/// Returns the parent of the given node in the node tree.
///
Expand Down

0 comments on commit 005a773

Please sign in to comment.