Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Settings/Pages/ThemeSettings/ThemeSettingsView.swift (Swift)

Code before:
                                Button {
                                    // TODO: #1874
                                } label: {
                                    Text("Export All Custom Themes...")
                                }.disabled(true)
                            }
                        })
                        .padding(.horizontal, 5)
                        .help("Import or Export Custom Themes")
                    }
                }
                if themeSearchQuery.isEmpty {
                    Section {
                        changeThemeOnSystemAppearance
                        if settings.matchAppearance {
                            alwaysUseDarkTerminalAppearance
                        }
                        useThemeBackground
                    }
                }
                Section {
                    VStack(spacing: 0) {
                        ForEach(filteredThemes) { theme in
                            Divider().padding(.horizontal, 10)
                            ThemeSettingsThemeRow(
                                theme: $themeModel.themes[themeModel.themes.firstIndex(of: theme)!],
                                active: themeModel.getThemeActive(theme)
                            ).id(theme)
                        }
                    }
                    .padding(-10)
                } footer: {
                    HStack {
                        Spacer()
                        Button("Import...") {
                            themeModel.importTheme()
                        }
                    }
                    .padding(.top, 10)
                }
                .sheet(item: $themeModel.detailsTheme) {
                    themeModel.isAdding = false
                } content: { theme in
                    if let index = themeModel.themes.firstIndex(where: {
                        $0.fileURL?.absoluteString == theme.fileURL?.absoluteString
                    }) {
                        ThemeSettingsThemeDetails(theme: Binding(
                            get: { themeModel.themes[index] },
                            set: { newValue in
                                themeModel.themes[index] = newValue
                                themeModel.save(newValue)

Review comment (bug):
I'm getting a crash here whenever deleting a theme while searching. For example deleting the theme here without clearing the search field.

![Screenshot 2024-09-11 at 10 43 21 PM](https://github.com/user-attachments/assets/7c7f292d-c851-454f-b7e6-088f1a0bc2f8)


Code after:
                                Button {
                                    // TODO: #1874
                                } label: {
                                    Text("Export All Custom Themes...")
                                }.disabled(true)
                            }
                        })
                        .padding(.horizontal, 5)
                        .help("Import or Export Custom Themes")
                    }
                }
                if themeSearchQuery.isEmpty {
                    Section {
                        changeThemeOnSystemAppearance
                        if settings.matchAppearance {
                            alwaysUseDarkTerminalAppearance
                        }
                        useThemeBackground
                    }
                }
                Section {
                    VStack(spacing: 0) {
                        ForEach(filteredThemes) { theme in
                            if let themeIndex = themeModel.themes.firstIndex(of: theme) {
                                Divider().padding(.horizontal, 10)
                                ThemeSettingsThemeRow(
                                    theme: $themeModel.themes[themeIndex],
                                    active: themeModel.getThemeActive(theme)
                                ).id(theme)
                            }
                        }
                    }
                    .padding(-10)
                } footer: {
                    HStack {
                        Spacer()
                        Button("Import...") {
                            themeModel.importTheme()
                        }
                    }
                    .padding(.top, 10)
                }
                .sheet(item: $themeModel.detailsTheme) {
                    themeModel.isAdding = false
                } content: { theme in
                    if let index = themeModel.themes.firstIndex(where: {
                        $0.fileURL?.absoluteString == theme.fileURL?.absoluteString
                    }) {
                        ThemeSettingsThemeDetails(theme: Binding(
                            get: { themeModel.themes[index] },
                            set: { newValue in