added tab explore/combine hotkeys - fixes #5703

This commit is contained in:
Eugene Pankov 2022-02-22 22:46:06 +01:00
parent fdca83ff27
commit 177a988292
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
8 changed files with 83 additions and 1 deletions

View File

@ -112,6 +112,12 @@ export class AppRootComponent {
if (hotkey === 'duplicate-tab') {
this.app.duplicateTab(this.app.activeTab)
}
if (hotkey === 'explode-tab' && this.app.activeTab instanceof SplitTabComponent) {
this.app.explodeTab(this.app.activeTab)
}
if (hotkey === 'combine-tabs' && this.app.activeTab instanceof SplitTabComponent) {
this.app.combineTabsInto(this.app.activeTab)
}
}
if (hotkey === 'reopen-tab') {
this.app.reopenLastTab()

View File

@ -82,6 +82,18 @@ export class SplitContainer {
this.ratios = this.ratios.map(x => x / s)
}
/**
* Makes all tabs have the same size
*/
equalize (): void {
for (const child of this.children) {
if (child instanceof SplitContainer) {
child.equalize()
}
}
this.ratios.fill(1 / this.ratios.length)
}
/**
* Gets the left/top side offset for the given element index (between 0 and 1)
*/
@ -449,6 +461,8 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
this.attachTabView(tab)
this.onAfterTabAdded(tab)
}
this.root.normalize()
}
removeTab (tab: BaseTabComponent): void {
@ -644,6 +658,11 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
}
}
equalize (): void {
this.root.normalize()
this.root.equalize()
}
private updateTitle (): void {
this.setTitle([...new Set(this.getAllTabs().map(x => x.title))].join(' | '))
}

View File

@ -13,7 +13,8 @@
div {
background: rgba(0, 0, 0, .7);
padding: 20px 30px;
font-size: 18px;
margin: 20px;
font-size: 16px;
color: #fff;
display: flex;
align-items: center;

View File

@ -21,6 +21,10 @@ hotkeys:
rearrange-panes:
- 'Ctrl-Shift'
duplicate-tab: []
explode-tab:
- 'Ctrl-Shift-.'
combine-tabs:
- 'Ctrl-Shift-,'
tab-1:
- 'Alt-1'
tab-2:

View File

@ -39,6 +39,10 @@ hotkeys:
tab-10:
- '⌘-0'
duplicate-tab: []
explode-tab:
- '⌘-Shift-.'
combine-tabs:
- '⌘-Shift-,'
tab-11: []
tab-12: []
tab-13: []

View File

@ -22,6 +22,10 @@ hotkeys:
rearrange-panes:
- 'Ctrl-Shift'
duplicate-tab: []
explode-tab:
- 'Ctrl-Shift-.'
combine-tab:
- 'Ctrl-Shift-,'
tab-1:
- 'Alt-1'
tab-2:

View File

@ -56,6 +56,14 @@ export class AppHotkeyProvider extends HotkeyProvider {
id: 'duplicate-tab',
name: this.translate.instant('Duplicate tab'),
},
{
id: 'explode-tab',
name: this.translate.instant('Turn current tab\'s panes into separate tabs'),
},
{
id: 'combine-tabs',
name: this.translate.instant('Combine all tabs into the current tab'),
},
{
id: 'tab-1',
name: this.translate.instant('Tab {number}', { number: 1 }),

View File

@ -399,4 +399,40 @@ export class AppService {
showSelector <T> (name: string, options: SelectorOption<T>[]): Promise<T> {
return this.selector.show(name, options)
}
explodeTab (tab: SplitTabComponent): SplitTabComponent[] {
const result: SplitTabComponent[] = []
for (const child of tab.getAllTabs().slice(1)) {
tab.removeTab(child)
result.push(this.wrapAndAddTab(child))
}
return result
}
combineTabsInto (into: SplitTabComponent): void {
this.explodeTab(into)
let allChildren: BaseTabComponent[] = []
for (const tab of this.tabs) {
if (into === tab) {
continue
}
let children = [tab]
if (tab instanceof SplitTabComponent) {
children = tab.getAllTabs()
}
allChildren = allChildren.concat(children)
}
let x = 1
let previous: BaseTabComponent|null = null
const stride = Math.ceil(Math.sqrt(allChildren.length + 1))
for (const child of allChildren) {
into.add(child, x ? previous : null, x ? 'r' : 'b')
previous = child
x = (x + 1) % stride
}
into.equalize()
}
}