Conversation
…across all extensions Migrates 12 files / 30+ call sites of the duplicated 'guard let tabIndex = tabManager.selectedTabIndex, tabIndex < tabManager.tabs.count' pattern to selectedTabAndIndex (write-back paths) or selectedTab (read-only paths). Both helpers were introduced in PR #939 and #940; this PR completes the migration outside Pagination and RowOperations. Files touched: - MainContentCoordinator.swift: runQuery, executeTableTabQueryDirectly, loadQueryIntoEditor, insertQueryFromAI, runExplainQuery, executeQueryInternal, handleSort, EXPLAIN error fallback - MainContentCoordinator+ClickHouse.swift: runVariantExplain - MainContentCoordinator+ColumnVisibility.swift: saveColumnVisibilityToTab - MainContentCoordinator+Discard.swift: handleDiscard (two sites) - MainContentCoordinator+ExecuteAll.swift: runAllStatements - MainContentCoordinator+Favorites.swift: insertFavorite, runFavoriteInNewTab - MainContentCoordinator+Filtering.swift: applyFilters, clearFiltersAndReload, restoreFiltersForTable - MainContentCoordinator+FKNavigation.swift: navigateToFKReference (four sites) - MainContentCoordinator+LoadMore.swift: loadMoreRows, fetchAllRows - MainContentCoordinator+Navigation.swift: openTableTab (four sites), promotePreviewTab - MainContentCoordinator+QueryParameters.swift: executeQueryWithParameters, executeQueryInternalParameterized, executeMultipleStatementsWithParameters - MainContentCoordinator+Refresh.swift: handleRefresh (three sites) - MainContentCommandActions.swift: formatQuery, toggleResults, previousResultTab, nextResultTab Behavior unchanged. Each migration preserves the original tab-not-selected and out-of-bounds short-circuits via selectedTabAndIndex's atomic check. Read-only paths use selectedTab (no fallback divergence — these don't use the index, so the strict-bounds requirement is moot). The dispatchParameterizedStatements / dispatchStatements helpers (called via tabIndex parameter, not selectedTabIndex) were left alone — they take the index from the caller's already-validated lookup. ExecuteAll's tabIndex parameter pattern preserved. Smoke-tested across query execution, EXPLAIN, table open from sidebar, FK navigation, filter apply/clear, refresh, discard dialog, pagination, format query, toggle results, insert favorite. Targeted tests pass.
…as (tab, tabIndex)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Completes the
selectedTabAndIndexmigration across 13 files / 30+ call sites. Closes the parking lot for this pattern. −104 / +81 LOC (net −23, but the more meaningful win is consistency: every active-tab lookup now uses one of two named helpers instead of the inline three-line pattern).What was migrated
Every site that used
guard let tabIndex = tabManager.selectedTabIndex, tabIndex < tabManager.tabs.count else { return }followed bylet tab = tabManager.tabs[tabIndex]:MainContentCoordinator.swiftrunQuery,executeTableTabQueryDirectly,loadQueryIntoEditor,insertQueryFromAI,runExplainQuery,executeQueryInternal,handleSort, EXPLAIN error fallback+ClickHouse.swiftrunVariantExplain+ColumnVisibility.swiftsaveColumnVisibilityToTab+Discard.swifthandleDiscard(two sites)+ExecuteAll.swiftrunAllStatements+Favorites.swiftinsertFavorite,runFavoriteInNewTab+Filtering.swiftapplyFilters,clearFiltersAndReload,restoreFiltersForTable+FKNavigation.swiftnavigateToFKReference(four sites)+LoadMore.swiftloadMoreRows,fetchAllRows+Navigation.swiftopenTableTab(four sites),promotePreviewTab+QueryParameters.swiftexecuteQueryWithParameters,executeQueryInternalParameterized,executeMultipleStatementsWithParameters+Refresh.swifthandleRefresh(three sites)MainContentCommandActions.swiftformatQuery,toggleResults,previousResultTab,nextResultTabPattern
tabManager.tabs[i]):selectedTabAndIndexreturning(tab, index).selectedTab, plus an explicit(tab, _)fromselectedTabAndIndexwhere strict bounds-check equivalence is preferred.(tab, tabIndex)destructured.Behavior
Unchanged. Each migration preserves the original short-circuits (no tab selected, out-of-bounds, etc.) via
selectedTabAndIndex's atomic bounds check. The minor exception was that read-only methods previously didtabs[index]after just an optional check — those now strictly bounds-check viaselectedTabAndIndex, a tiny safety improvement.The
dispatchParameterizedStatements/dispatchStatementshelpers (called viatabIndexparameter, notselectedTabIndex) were left alone — they take the index from the caller's already-validated lookup.ExecuteAll'stabIndexparameter pattern preserved.Test plan
TableRowsMutationTests,SortCacheInvalidationTests,EvictionTests,QueryTabManagerSelectedTabAndIndexTests,RowOperationsDispatchTests)What's next (parking lot, future PRs)
The
selectedTabAndIndexpattern is now the canonical lookup. With it in place, the next coordinator dedup target would be:confirmDiscardChangesIfNeededcallback pattern (used in Pagination, Filtering, Navigation — each captures its own copy oftabIndex/tabIdvia[weak self]then re-validates inside the callback). Could move to a per-action helper.tabManager.tabs[tabIndex].execution.errorMessage = ...pattern for safe-mode error reporting (used 5+ times). Could become asetExecutionError(_:on:)helper on the coordinator.Both warrant separate focused PRs.