Skip to content

Commit 8f26014

Browse files
authored
Fix: Filename with whitespaces and new lines (#1629)
fix: filename with whitespaces and new lines issue
1 parent 1f099d9 commit 8f26014

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFile.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, Editor
3939
var id: String { url.relativePath }
4040

4141
/// Returns the file name (e.g.: `Package.swift`)
42-
var name: String { url.lastPathComponent }
42+
var name: String { url.lastPathComponent.trimmingCharacters(in: .whitespacesAndNewlines) }
4343

4444
/// Returns the extension of the file or an empty string if no extension is present.
4545
var type: FileIcon.FileType { .init(rawValue: url.pathExtension) ?? .txt }
@@ -176,7 +176,9 @@ final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, Editor
176176

177177
/// Returns the file name with optional extension (e.g.: `Package.swift`)
178178
func fileName(typeHidden: Bool = false) -> String {
179-
typeHidden ? url.deletingPathExtension().lastPathComponent : name
179+
typeHidden ? url.deletingPathExtension()
180+
.lastPathComponent
181+
.trimmingCharacters(in: .whitespacesAndNewlines) : name
180182
}
181183

182184
/// Generates a string based on user's file name preferences.

0 commit comments

Comments
 (0)