show selected tab in multitab

This commit is contained in:
Jan Prochazka 2023-03-05 12:20:07 +01:00
parent d283429f40
commit f5d41c89e6
3 changed files with 32 additions and 24 deletions

View File

@ -1,42 +1,28 @@
<script lang="ts">
import _ from 'lodash';
import { currentDatabase, lockedDatabaseMode, openedTabs, TabDefinition } from '../stores';
import { openedTabs } from '../stores';
import TabContent from './TabContent.svelte';
import tabs from '../tabs';
import { shouldShowTab } from './TabsPanel.svelte';
export let multiTabIndex;
export let shownTab;
let mountedTabs = {};
function findShownTab(tabs: TabDefinition[], multiTabIndex, lockedDbMode, currentDb) {
const selectedTab = tabs.find(x => x.selected && x.closedTime == null && (x.multiTabIndex || 0) == multiTabIndex);
if (selectedTab) {
return selectedTab;
}
const selectedIndex = _.findLastIndex(
tabs,
x => (x.multiTabIndex || 0) == multiTabIndex && shouldShowTab(x, lockedDbMode, currentDb)
);
return tabs[selectedIndex];
}
$: shownTab = findShownTab($openedTabs, multiTabIndex, $lockedDatabaseMode, $currentDatabase);
// cleanup closed tabs
$: {
if (
_.difference(
_.keys(mountedTabs),
_.map(
$openedTabs.filter(x => x.closedTime == null),
$openedTabs.filter(x => x.closedTime == null && (x.multiTabIndex || 0) == multiTabIndex),
'tabid'
)
).length > 0
) {
mountedTabs = _.pickBy(mountedTabs, (v, k) => $openedTabs.find(x => x.tabid == k && x.closedTime == null));
mountedTabs = _.pickBy(mountedTabs, (v, k) =>
$openedTabs.find(x => x.tabid == k && x.closedTime == null && (x.multiTabIndex || 0) == multiTabIndex)
);
}
}

View File

@ -1,15 +1,34 @@
<script lang='ts'>
<script lang="ts">
import TabRegister from './TabRegister.svelte';
import TabsPanel from './TabsPanel.svelte';
import _ from 'lodash';
import { currentDatabase, lockedDatabaseMode, openedTabs, TabDefinition } from '../stores';
import { shouldShowTab } from './TabsPanel.svelte';
export let multiTabIndex;
function findShownTab(tabs: TabDefinition[], multiTabIndex, lockedDbMode, currentDb) {
const selectedTab = tabs.find(x => x.selected && x.closedTime == null && (x.multiTabIndex || 0) == multiTabIndex);
if (selectedTab) {
return selectedTab;
}
const selectedIndex = _.findLastIndex(
tabs,
x => (x.multiTabIndex || 0) == multiTabIndex && shouldShowTab(x, lockedDbMode, currentDb)
);
return tabs[selectedIndex];
}
$: shownTab = findShownTab($openedTabs, multiTabIndex, $lockedDatabaseMode, $currentDatabase);
</script>
<div class="tabs">
<TabsPanel {multiTabIndex} />
<TabsPanel {multiTabIndex} {shownTab} />
</div>
<div class="content">
<TabRegister {multiTabIndex} />
<TabRegister {multiTabIndex} {shownTab} />
</div>
<style>

View File

@ -281,6 +281,7 @@
import CloseTabModal from '../modals/CloseTabModal.svelte';
export let multiTabIndex;
export let shownTab;
$: showTabFilterFunc = tab =>
shouldShowTab(tab, $lockedDatabaseMode, $currentDatabase) && (tab.multiTabIndex || 0) == multiTabIndex;
@ -517,7 +518,9 @@
<div
id={`file-tab-item-${tab.tabid}`}
class="file-tab-item"
class:selected={$draggingTab || $draggingDbGroup ? tab.tabid == $draggingTabTarget?.tabid : tab.selected}
class:selected={$draggingTab || $draggingDbGroup
? tab.tabid == $draggingTabTarget?.tabid
: tab.tabid == shownTab?.tabid}
on:click={e => handleTabClick(e, tab.tabid)}
on:mouseup={e => handleMouseUp(e, tab.tabid)}
use:contextMenu={getContextMenu(tab)}