Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/NavigatorSidebar/NavigatorSidebarToolbarTop.swift (Swift)

Code before:
        }
        .frame(height: 29, alignment: .center)
        .frame(maxWidth: .infinity)
        .overlay(alignment: .top) {
            Divider()
        }
        .overlay(alignment: .bottom) {
            Divider()
        }
        .animation(.default, value: icons)
    }

    private func makeIcon(named: String, title: String, id: Int, scale: Image.Scale = .medium) -> some View {
        Button {
            selection = id
        } label: {
            getSafeImage(named: named, accesibilityDescription: title)
            .help(title)
            .onDrag {
            if let index = icons.firstIndex(where: { $0.imageName == named }) {
                draggingItem = icons[index]
            }
                return .init(object: NSString(string: named))
            } preview: {
                RoundedRectangle(cornerRadius: .zero)
                    .frame(width: .zero)
            }
        }
        .buttonStyle(NavigatorToolbarButtonStyle(id: id, selection: selection, activeState: activeState))
        .imageScale(scale)
    }

    private func getSafeImage(named: String, accesibilityDescription: String?) -> Image {
        if let nsImage = NSImage(systemSymbolName: named, accessibilityDescription: accesibilityDescription) {
            return Image(nsImage: nsImage)
        } else {
            return Image(symbol: named)
        }
    }

    struct NavigatorToolbarButtonStyle: ButtonStyle {
        var id: Int
        var selection: Int
        var activeState: ControlActiveState

        func makeBody(configuration: Configuration) -> some View {
            configuration.label
                .font(.system(size: 12, weight: id == selection ? .semibold : .regular))
                .symbolVariant(id == selection ? .fill : .none)
                .foregroundColor(id == selection ? .accentColor : configuration.isPressed ? .primary : .secondary)
                .frame(width: 25, height: 25, alignment: .center)

Review comment (suggestion):
Wouldn't it be better to use `.fit` instead? `.fill` might lead to cut-off icons if they are particularly wide or tall.

Code after:
                }
            }
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .overlay(alignment: .top) {
                Divider()
            }
            .overlay(alignment: .bottom) {
                Divider()
            }
            .animation(.default, value: icons)
        }
        .frame(maxWidth: .infinity, idealHeight: 29)
        .fixedSize(horizontal: false, vertical: true)
    }

    private func makeSpace(for size: CGSize) -> CGFloat {
        size.width < 270 ? 9 : 15
    }

    private func makeIcon(named: String, title: String, id: Int, scale: Image.Scale = .medium) -> some View {
        Button {
            selection = id
        } label: {
            getSafeImage(named: named, accesibilityDescription: title)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .help(title)
                .onDrag {
                    if let index = icons.firstIndex(where: { $0.imageName == named }) {
                        draggingItem = icons[index]
                    }
                    return .init(object: NSString(string: named))
                } preview: {
                    RoundedRectangle(cornerRadius: .zero)
                        .frame(width: .zero)
                }
        }
        .buttonStyle(NavigatorToolbarButtonStyle(id: id, selection: selection, activeState: activeState))
    }

    private func getSafeImage(named: String, accesibilityDescription: String?) -> Image {
        if let nsImage = NSImage(systemSymbolName: named, accessibilityDescription: accesibilityDescription) {
            return Image(nsImage: nsImage)
        } else {
            return Image(symbol: named)
        }
    }

    struct NavigatorToolbarButtonStyle: ButtonStyle {
        var id: Int
        var selection: Int