Skip to content

Commit d8fe665

Browse files
committed
fix: preserve built-in theme display order
1 parent 432e649 commit d8fe665

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

TablePro/Theme/ThemeStorage.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ internal struct ThemeStorage {
215215
}
216216
}
217217

218+
private static let builtInThemeOrder = [
219+
"tablepro.default-light",
220+
"tablepro.default-dark",
221+
"tablepro.dracula",
222+
"tablepro.solarized-light",
223+
"tablepro.solarized-dark",
224+
"tablepro.one-dark",
225+
"tablepro.github-light",
226+
"tablepro.github-dark",
227+
"tablepro.nord",
228+
]
229+
218230
private static func loadBuiltInThemes(from directory: URL) -> [ThemeDefinition] {
219231
let fm = FileManager.default
220232
guard fm.fileExists(atPath: directory.path) else { return [] }
@@ -223,7 +235,12 @@ internal struct ThemeStorage {
223235
let files = try fm.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil)
224236
.filter { $0.pathExtension == "json" && $0.lastPathComponent.hasPrefix("tablepro.") }
225237

226-
return files.compactMap { loadTheme(from: $0) }
238+
let themes = files.compactMap { loadTheme(from: $0) }
239+
return themes.sorted { lhs, rhs in
240+
let li = builtInThemeOrder.firstIndex(of: lhs.id) ?? Int.max
241+
let ri = builtInThemeOrder.firstIndex(of: rhs.id) ?? Int.max
242+
return li < ri
243+
}
227244
} catch {
228245
logger.error("Failed to list built-in themes: \(error)")
229246
return []

0 commit comments

Comments
 (0)