@@ -45,13 +45,15 @@ struct EditorView: View {
4545 . foregroundStyle ( . secondary)
4646
4747 if let file = selectedFile {
48+ let iconInfo = FileIconHelper . iconInfo ( for: file. name, isDirectory: false )
49+
4850 Image ( systemName: " chevron.right " )
4951 . font ( . system( size: 9 ) )
5052 . foregroundStyle ( . quaternary)
5153
52- Image ( systemName: iconForFile ( file . name) )
54+ Image ( systemName: iconInfo . name)
5355 . font ( . system( size: 12 ) )
54- . foregroundStyle ( colorForFile ( file . name ) )
56+ . foregroundStyle ( iconInfo . color )
5557
5658 Text ( file. name)
5759 . font ( . system( size: 13 , weight: . medium) )
@@ -100,7 +102,7 @@ struct EditorView: View {
100102 HStack ( spacing: 4 ) {
101103 Image ( systemName: " chevron.left.forwardslash.chevron.right " )
102104 . font ( . system( size: 9 ) )
103- Text ( languageDisplayName ( currentLanguage) )
105+ Text ( FileIconHelper . languageDisplayName ( currentLanguage) )
104106 . font ( . system( size: 11 ) )
105107 }
106108 . foregroundStyle ( . secondary)
@@ -145,68 +147,11 @@ struct EditorView: View {
145147
146148 // MARK: - Helpers
147149
148- private func iconForFile( _ filename: String ) -> String {
149- let ext = ( filename as NSString ) . pathExtension. lowercased ( )
150- switch ext {
151- case " swift " : return " swift "
152- case " java " , " kt " , " kts " : return " cup.and.saucer.fill "
153- case " js " : return " j.square.fill "
154- case " ts " : return " t.square.fill "
155- case " py " : return " p.square.fill "
156- case " json " : return " curlybraces "
157- case " md " : return " doc.richtext.fill "
158- case " html " , " css " : return " globe "
159- case " yml " , " yaml " : return " list.bullet.rectangle.fill "
160- case " sh " : return " terminal.fill "
161- case " dockerfile " : return " shippingbox.fill "
162- default : return " doc.text.fill "
163- }
164- }
165-
166- private func colorForFile( _ filename: String ) -> Color {
167- let ext = ( filename as NSString ) . pathExtension. lowercased ( )
168- switch ext {
169- case " swift " : return . orange
170- case " java " : return . red
171- case " kt " , " kts " : return . purple
172- case " js " : return . yellow
173- case " ts " : return . blue
174- case " py " : return . cyan
175- case " json " : return . yellow
176- case " md " : return . blue
177- case " html " : return . orange
178- case " css " : return . pink
179- case " yml " , " yaml " : return . pink
180- case " sh " : return . green
181- default : return . secondary
182- }
183- }
184-
185- private func languageDisplayName( _ lang: String ) -> String {
186- switch lang {
187- case " swift " : return " Swift "
188- case " java " : return " Java "
189- case " kotlin " : return " Kotlin "
190- case " javascript " : return " JavaScript "
191- case " typescript " : return " TypeScript "
192- case " python " : return " Python "
193- case " json " : return " JSON "
194- case " html " : return " HTML "
195- case " css " : return " CSS "
196- case " markdown " : return " Markdown "
197- case " yaml " : return " YAML "
198- case " shell " : return " Shell "
199- case " dockerfile " : return " Dockerfile "
200- case " plaintext " : return " Plain Text "
201- default : return lang. capitalized
202- }
203- }
204-
205150 private func loadFile( _ file: FileItem ) {
206151 guard !file. isDirectory else { return }
207152
208153 isLoadingFile = true
209- currentLanguage = detectLanguage ( for: file. name)
154+ currentLanguage = FileIconHelper . languageName ( for: file. name)
210155
211156 Task {
212157 do {
@@ -253,32 +198,4 @@ struct EditorView: View {
253198 }
254199 }
255200 }
256-
257- private func detectLanguage( for filename: String ) -> String {
258- let ext = ( filename as NSString ) . pathExtension. lowercased ( )
259- switch ext {
260- case " swift " : return " swift "
261- case " js " : return " javascript "
262- case " ts " : return " typescript "
263- case " py " : return " python "
264- case " java " : return " java "
265- case " kt " , " kts " : return " kotlin "
266- case " json " : return " json "
267- case " html " : return " html "
268- case " css " : return " css "
269- case " md " : return " markdown "
270- case " yaml " , " yml " : return " yaml "
271- case " xml " : return " xml "
272- case " sh " : return " shell "
273- case " c " , " h " : return " c "
274- case " cpp " , " hpp " : return " cpp "
275- case " go " : return " go "
276- case " rs " : return " rust "
277- case " rb " : return " ruby "
278- case " php " : return " php "
279- case " sql " : return " sql "
280- case " dockerfile " : return " dockerfile "
281- default : return " plaintext "
282- }
283- }
284201}
0 commit comments