Skip to content

Fix: Filename with whitespaces and new lines #1629

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

Merged
merged 1 commit into from
Mar 18, 2024
Merged
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
6 changes: 4 additions & 2 deletions CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, Editor
var id: String { url.relativePath }

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

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

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

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