Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Editor/Models/Editor.swift (Swift)

Code before:
        self.temporaryTab = temporaryTab
    }

    /// Closes the editor.
    func close() {
        parent?.closeEditor(with: id)
    }

    /// Gets the editor layout.
    func getEditorLayout() -> EditorLayout? {
        return parent?.getEditorLayout(with: id)
    }

    /// Set the selected tab. Loads the file's contents if it hasn't already been opened.
    /// - Parameter file: The file to set as the selected tab.
    func setSelectedTab(_ file: CEWorkspaceFile?) {
        guard let file else {
            selectedTab = nil
            return
        }
        guard let tab = self.tabs.first(where: { $0.file == file }) else {
            return
        }
        self.selectedTab = tab
        if tab.file.fileDocument == nil {
            do { // eat this error for ease of API use.
                try openFile(item: tab)
            } catch {
                print(error)
            }
        }
    }

    /// Closes a tab in the editor.
    /// This will also write any changes to the file on disk and will add the tab to the tab history.
    /// - Parameters:
    ///   - file: The tab to close
    ///   - fromHistory: If `true`, does not clear tabs ahead of the ``historyOffset``
    ///                  Used when opening tabs from the history queue where tabs ahead of the ``historyOffset`` should
    ///                  not be removed.
    func closeTab(file: CEWorkspaceFile, fromHistory: Bool = false) {
        guard canCloseTab(file: file) else { return }

        if temporaryTab?.file == file {
            temporaryTab = nil
        }
        if !fromHistory {
            clearFuture()
        }
        if file != selectedTab?.file {
            addToHistory(EditorInstance(file: file))

Review comment (suggestion):
```suggestion
            do { // Ignore this error for simpler API usage.


Code after:
        self.temporaryTab = temporaryTab
    }

    /// Closes the editor.
    func close() {
        parent?.closeEditor(with: id)
    }

    /// Gets the editor layout.
    func getEditorLayout() -> EditorLayout? {
        return parent?.getEditorLayout(with: id)
    }

    /// Set the selected tab. Loads the file's contents if it hasn't already been opened.
    /// - Parameter file: The file to set as the selected tab.
    func setSelectedTab(_ file: CEWorkspaceFile?) {
        guard let file else {
            selectedTab = nil
            return
        }
        guard let tab = self.tabs.first(where: { $0.file == file }) else {
            return
        }
        self.selectedTab = tab
        if tab.file.fileDocument == nil {
            do { // Ignore this error for simpler API usage.
                try openFile(item: tab)
            } catch {
                print(error)
            }
        }
    }

    /// Closes a tab in the editor.
    /// This will also write any changes to the file on disk and will add the tab to the tab history.
    /// - Parameters:
    ///   - file: The tab to close
    ///   - fromHistory: If `true`, does not clear tabs ahead of the ``historyOffset``
    ///                  Used when opening tabs from the history queue where tabs ahead of the ``historyOffset`` should
    ///                  not be removed.
    func closeTab(file: CEWorkspaceFile, fromHistory: Bool = false) {
        guard canCloseTab(file: file) else { return }

        if temporaryTab?.file == file {
            temporaryTab = nil
        }
        if !fromHistory {
            clearFuture()
        }
        if file != selectedTab?.file {
            addToHistory(EditorInstance(file: file))