1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-27 00:50:49 +03:00

prevent dropping a tab on itself - fixes #5580

This commit is contained in:
Eugene Pankov 2022-01-29 19:28:19 +01:00
parent 63374f532c
commit ceb1b59409
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
2 changed files with 17 additions and 2 deletions

View File

@ -158,6 +158,7 @@ export type SplitDropZoneInfo = {
></split-tab-spanner>
<split-tab-drop-zone
*ngFor='let dropZone of _dropZones'
[enabled]='dropZonesEnabled'
[parent]='this'
[dropZone]='dropZone'
(tabDropped)='onTabDropped($event, dropZone)'
@ -603,6 +604,10 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
this.tabAdopted.next(tab)
}
get dropZonesEnabled (): boolean {
return this.getAllTabs().length > 1
}
destroy (): void {
super.destroy()
for (const x of this.getAllTabs()) {

View File

@ -23,22 +23,32 @@ import { SplitDropZoneInfo } from './splitTab.component'
export class SplitTabDropZoneComponent extends SelfPositioningComponent {
@Input() dropZone: SplitDropZoneInfo
@Input() parent: BaseTabComponent
@Input() enabled = false
@Output() tabDropped = new EventEmitter<BaseTabComponent>()
@HostBinding('class.active') isActive = false
@HostBinding('class.highlighted') isHighlighted = false
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor (
element: ElementRef,
app: AppService,
) {
super(element)
this.subscribeUntilDestroyed(app.tabDragActive$, tab => {
this.isActive = !!tab && tab !== this.parent && (this.dropZone.type === 'relative' || tab !== this.dropZone.container.children[this.dropZone.position])
this.isActive = !!(tab && this.canActivateFor(tab))
this.layout()
})
}
canActivateFor (tab: BaseTabComponent) {
if (tab === this.parent || !this.enabled) {
return false
}
if (this.dropZone.type === 'absolute' && tab === this.dropZone.container.children[this.dropZone.position]) {
return false
}
return true
}
ngOnChanges () {
this.layout()
}