Skip to content

Commit

Permalink
Merge pull request #6140 from ChristianBingman/pane-resizing-with-hot…
Browse files Browse the repository at this point in the history
…keys
  • Loading branch information
Eugeny authored Apr 12, 2022
2 parents 95ae4b8 + be72cd5 commit 5c04c11
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tabby-core/src/components/splitTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { TabRecoveryProvider, RecoveryToken } from '../api/tabRecovery'
import { TabsService, NewTabParameters } from '../services/tabs.service'
import { HotkeysService } from '../services/hotkeys.service'
import { TabRecoveryService } from '../services/tabRecovery.service'
import { ConfigService } from '../api'

export type SplitOrientation = 'v' | 'h'
export type SplitDirection = 'r' | 't' | 'b' | 'l'
export type ResizeDirection = 'v' | 'h' | 'dv' | 'dh'

/**
* Describes a horizontal or vertical split row or column
Expand Down Expand Up @@ -250,6 +252,7 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
private hotkeys: HotkeysService,
private tabsService: TabsService,
private tabRecovery: TabRecoveryService,
private config: ConfigService,
) {
super()
this.root = new SplitContainer()
Expand Down Expand Up @@ -313,6 +316,18 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
case 'close-pane':
this.removeTab(this.focusedTab)
break
case 'pane-increase-vertical':
this.resizePane('v')
break
case 'pane-decrease-vertical':
this.resizePane('dv')
break
case 'pane-increase-horizontal':
this.resizePane('h')
break
case 'pane-decrease-horizontal':
this.resizePane('dh')
break
}
})
}
Expand Down Expand Up @@ -504,6 +519,75 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
this.updateTitle()
}

/**
* Changes the size of the focused pane in the given direction
*/
resizePane (direction: ResizeDirection): void {
const resizeStep = this.config.store.terminal.paneResizeStep

// The direction of the resize pane, vertically or horizontally
let directionvh: SplitOrientation = 'h'

const isDecreasing: boolean = direction === 'dv' || direction === 'dh'

if (direction === 'dh') {
directionvh = 'h'
}
if (direction === 'dv') {
directionvh = 'v'
}
if (direction === 'h') {
directionvh = 'h'
}
if (direction === 'v') {
directionvh = 'v'
}
if (!this.focusedTab) {
console.debug('No currently focused tab')
return
}

let currentContainer: BaseTabComponent | SplitContainer = this.focusedTab
let child: BaseTabComponent | SplitContainer | null = this.focusedTab
let curSplitOrientation: SplitOrientation | null = null

// Find the first split that is in the orientations that the user chooses to change
while (curSplitOrientation !== directionvh) {
const parentContainer = this.getParentOf(currentContainer)
if (!parentContainer) {
return
}
child = currentContainer
currentContainer = parentContainer
if (currentContainer instanceof SplitContainer) {
curSplitOrientation = currentContainer.orientation
}
}

if (!(currentContainer instanceof SplitContainer)) {
return
}

// Determine which index in the ratios refers to the child that will be modified
const currentChildIndex = currentContainer.children.indexOf(child)

let updatedRatio = 0
if (isDecreasing) {
updatedRatio = currentContainer.ratios[currentChildIndex] - resizeStep
if (updatedRatio < 0) {
return
}
} else {
updatedRatio = currentContainer.ratios[currentChildIndex] + resizeStep
if (updatedRatio > 1) {
return
}
}

currentContainer.ratios[currentChildIndex] = updatedRatio
this.layout()
}

/**
* Moves focus in the given direction
*/
Expand Down
4 changes: 4 additions & 0 deletions tabby-core/src/configDefaults.linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ hotkeys:
- 'Ctrl-Alt-]'
pane-maximize:
- 'Ctrl-Alt-Enter'
pane-increase-vertical: []
pane-decrease-vertical: []
pane-increase-horizontal: []
pane-decrease-horizontal: []
close-pane: []
switch-profile:
- 'Ctrl-Alt-T'
Expand Down
4 changes: 4 additions & 0 deletions tabby-core/src/configDefaults.macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ hotkeys:
- '⌘-⌥-Enter'
close-pane:
- '⌘-Shift-W'
pane-increase-vertical: []
pane-decrease-vertical: []
pane-increase-horizontal: []
pane-decrease-horizontal: []
profile-selector:
- '⌘-E'
switch-profile:
Expand Down
4 changes: 4 additions & 0 deletions tabby-core/src/configDefaults.windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ hotkeys:
pane-maximize:
- 'Ctrl-Alt-Enter'
close-pane: []
pane-increase-vertical: []
pane-decrease-vertical: []
pane-increase-horizontal: []
pane-decrease-horizontal: []
switch-profile:
- 'Ctrl-Alt-T'
profile-selector:
Expand Down
1 change: 1 addition & 0 deletions tabby-core/src/configDefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ appearance:
terminal:
showBuiltinProfiles: true
showRecentProfiles: 3
paneResizeStep: 0.1
hotkeys:
profile:
__nonStructural: true
Expand Down
16 changes: 16 additions & 0 deletions tabby-core/src/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ export class AppHotkeyProvider extends HotkeyProvider {
id: 'close-pane',
name: this.translate.instant('Close focused pane'),
},
{
id: 'pane-increase-vertical',
name: this.translate.instant('Increase vertical split size'),
},
{
id: 'pane-decrease-vertical',
name: this.translate.instant('Decrease vertical split size'),
},
{
id: 'pane-increase-horizontal',
name: this.translate.instant('Increase horizontal split size'),
},
{
id: 'pane-decrease-horizontal',
name: this.translate.instant('Decrease horizontal split size'),
},
]

constructor (
Expand Down
15 changes: 15 additions & 0 deletions tabby-settings/src/components/windowSettingsTab.component.pug
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ h3.mt-4(translate) Tabs
(ngModelChange)='config.save();',
)

h3.mt-4(translate) Panes

.form-line()
.header
.title(translate) Pane resize step
.description(translate) For keyboard shortcuts
input(
type='range',
[(ngModel)]='config.store.terminal.paneResizeStep',
(ngModelChange)='saveConfiguration();',
min='0.1',
max='0.9',
step='0.05'
)

h3.mt-4(translate) Hacks

.form-line
Expand Down

0 comments on commit 5c04c11

Please sign in to comment.