Skip to content

Commit

Permalink
Merge pull request #934 from NguyenDuck/feat/ctrl-tab-recents
Browse files Browse the repository at this point in the history
feat: ctrl + tab switch to recent selected tab
  • Loading branch information
outercloudstudio authored Oct 26, 2023
2 parents 9887a13 + f928034 commit 17cdf69
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/components/TabSystem/TabSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IOpenTabOptions {
export class TabSystem extends MonacoHolder {
protected uuid = uuid()
public tabs = <Ref<Tab[]>>ref([])
protected _recentSelectedTab = <Ref<Tab | undefined>>ref(undefined)
protected _selectedTab = <Ref<Tab | undefined>>ref(undefined)
protected get tabTypes() {
return TabProvider.tabs
Expand Down Expand Up @@ -61,6 +62,10 @@ export class TabSystem extends MonacoHolder {
)
}

get recentSelectedTab() {
return this._recentSelectedTab.value
}

get selectedTab() {
return this._selectedTab.value
}
Expand Down Expand Up @@ -219,6 +224,24 @@ export class TabSystem extends MonacoHolder {
await previousTab.select()
}

async hasRecentTab() {
return this.recentSelectedTab !== undefined
}

async selectRecentTab() {
const tabs = this.tabs.value
if (tabs.length === 0) return

const recentTab = this.recentSelectedTab
if (!recentTab) return

await recentTab.select()
}

async saveRecentTab(tab?: Tab) {
this._recentSelectedTab.value = tab
}

async select(tab?: Tab) {
if (this.isActive.value !== !!tab) this.setActive(!!tab)

Expand All @@ -229,6 +252,8 @@ export class TabSystem extends MonacoHolder {
if (tab && tab !== this.selectedTab && this.project.isActiveProject) {
App.eventSystem.dispatch('currentTabSwitched', tab)
}

this.saveRecentTab(this.selectedTab)
this._selectedTab.value = tab

// Next steps don't need to be done if we simply unselect tab
Expand Down
6 changes: 5 additions & 1 deletion src/components/Toolbar/Category/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ export function setupViewCategory(app: App) {
description: 'toolbar.view.nextTab.description',
keyBinding: platform() === 'darwin' ? 'Meta + Tab' : 'Ctrl + Tab',
onTrigger: () => {
app.tabSystem?.selectNextTab()
if (app.tabSystem?.hasRecentTab()) {
app.tabSystem?.selectRecentTab()
} else {
app.tabSystem?.selectNextTab()
}
},
})
)
Expand Down

0 comments on commit 17cdf69

Please sign in to comment.