Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Documents/Controllers/CodeEditSplitViewController.swift (Swift)

Code before:
    }

    override func viewWillAppear() {
        super.viewWillAppear()
        let width = workspace.getFromWorkspaceState(key: self.widthStateName) as? CGFloat
        splitView.setPosition(width ?? .snapWidth, ofDividerAt: .zero)
        setWidthFromState = true
    }

    // MARK: - NSSplitViewDelegate

    override func splitView(
        _ splitView: NSSplitView,
        constrainSplitPosition proposedPosition: CGFloat,
        ofSubviewAt dividerIndex: Int
    ) -> CGFloat {
        if dividerIndex == 0 {
            // Navigator
            if (CGFloat.minSnapWidth...CGFloat.maxSnapWidth).contains(proposedPosition) {
                isSnapped = true
                return .snapWidth
            } else {
                isSnapped = false
                if proposedPosition <= CodeEditWindowController.minSidebarWidth / 2 {
                    splitViewItems.first?.isCollapsed = true
                    return 0
                }
                return max(CodeEditWindowController.minSidebarWidth, proposedPosition)
            }
        } else if dividerIndex == 1 {
            let proposedWidth = view.frame.width - proposedPosition
            if proposedWidth <= CodeEditWindowController.minSidebarWidth / 2 {
                splitViewItems.last?.isCollapsed = true
                removeToolbarItemIfNeeded()
                return proposedPosition
            }
            splitViewItems.last?.isCollapsed = false
            insertToolbarItemIfNeeded()
            return min(view.frame.width - CodeEditWindowController.minSidebarWidth, proposedPosition)
        }
        return proposedPosition
    }

    override func splitViewDidResizeSubviews(_ notification: Notification) {
        guard let resizedDivider = notification.userInfo?["NSSplitViewDividerIndex"] as? Int else {
            return
        }

        if resizedDivider == 0 {
            let panel = splitView.subviews[0]
            let width = panel.frame.size.width

Review comment (suggestion):
Found a little problem...

As discussed in #976, we should initialize the sidebar with a width only if the user-preferred width exists and is not the snap width, otherwise, the haptic feedback for snapping the sidebar will be triggered. Here's a suggested solution:

```suggestion
	/// Initialize the sidebar with user preferred width
    /// The width will only be set if the user preferred width is not equal to the snapWidth to prevent triggering the haptic feedback when initializing
	override func viewWillAppear() {
        super.viewWillAppear()
        let width = workspace.getFromWorkspaceState(key: self.widthStateName) as? CGFloat ?? .snapWidth
        if width != .snapWidth {
            splitView.setPosition(width, ofDividerAt: .zero)
            setWidthFromState = true
        }
    }
```

Code after:

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewWillAppear() {
        super.viewWillAppear()
        let width = workspace.getFromWorkspaceState(key: self.widthStateName) as? CGFloat
        splitView.setPosition(width ?? .snapWidth, ofDividerAt: .zero)
        setWidthFromState = true

        if let firstSplitView = splitViewItems.first {
            firstSplitView.isCollapsed = workspace.getFromWorkspaceState(
                key: isNavigatorCollapsedStateName
            ) as? Bool ?? false
        }

        if let lastSplitView = splitViewItems.last {
            lastSplitView.isCollapsed = workspace.getFromWorkspaceState(
                key: isInspectorCollapsedStateName
            ) as? Bool ?? true
        }

        self.insertToolbarItemIfNeeded()
    }

    // MARK: - NSSplitViewDelegate

    override func splitView(
        _ splitView: NSSplitView,
        constrainSplitPosition proposedPosition: CGFloat,
        ofSubviewAt dividerIndex: Int
    ) -> CGFloat {
        if dividerIndex == 0 {
            // Navigator
            if (CGFloat.minSnapWidth...CGFloat.maxSnapWidth).contains(proposedPosition) {
                isSnapped = true
                return .snapWidth
            } else {
                isSnapped = false
                if proposedPosition <= CodeEditWindowController.minSidebarWidth / 2 {
                    splitViewItems.first?.isCollapsed = true
                    return 0
                }
                return max(CodeEditWindowController.minSidebarWidth, proposedPosition)
            }
        } else if dividerIndex == 1 {
            let proposedWidth = view.frame.width - proposedPosition
            if proposedWidth <= CodeEditWindowController.minSidebarWidth / 2 {
                splitViewItems.last?.isCollapsed = true