| 486 | }; |
| 487 | |
| 488 | const upsertOpenTabDraft = ( |
| 489 | state: { openTmpTabList: PersistentTab[]; currentTabId: string }, |
| 490 | tab: SQLEditorTab, |
| 491 | beside: boolean |
| 492 | ) => { |
| 493 | const persistent = pick(tab, ...PERSISTENT_TAB_FIELDS) as PersistentTab; |
| 494 | const position = state.openTmpTabList.findIndex((item) => item.id === tab.id); |
| 495 | if (position >= 0) { |
| 496 | Object.assign(state.openTmpTabList[position], persistent); |
| 497 | return; |
| 498 | } |
| 499 | const currentPosition = state.openTmpTabList.findIndex( |
| 500 | (item) => item.id === state.currentTabId |
| 501 | ); |
| 502 | if (beside && currentPosition >= 0) { |
| 503 | state.openTmpTabList.splice(currentPosition + 1, 0, persistent); |
| 504 | } else { |
| 505 | state.openTmpTabList.push(persistent); |
| 506 | } |
| 507 | }; |
| 508 | |
| 509 | /** |
| 510 | * Direct (non-React) accessor. Mirrors Zustand's `getState()`. |