From 94d91f81821b8c23dbf82dbd3c2d2f1c63473485 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Mon, 30 Dec 2019 18:42:50 +0100 Subject: [PATCH] reset split ratio on double click (fixes #1377) --- .../components/splitTabSpanner.component.ts | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/terminus-core/src/components/splitTabSpanner.component.ts b/terminus-core/src/components/splitTabSpanner.component.ts index e0fb7805..e06ce5d4 100644 --- a/terminus-core/src/components/splitTabSpanner.component.ts +++ b/terminus-core/src/components/splitTabSpanner.component.ts @@ -23,6 +23,10 @@ export class SplitTabSpannerComponent { constructor (private element: ElementRef) { } ngAfterViewInit () { + this.element.nativeElement.addEventListener('dblclick', () => { + this.reset() + }) + this.element.nativeElement.addEventListener('mousedown', (e: MouseEvent) => { this.isActive = true const start = this.isVertical ? e.pageY : e.pageX @@ -49,14 +53,16 @@ export class SplitTabSpannerComponent { diff = Math.max(diff, -this.container.ratios[this.index - 1] + 0.1) diff = Math.min(diff, this.container.ratios[this.index] - 0.1) - this.container.ratios[this.index - 1] += diff - this.container.ratios[this.index] -= diff - this.change.emit() + if (diff) { + this.container.ratios[this.index - 1] += diff + this.container.ratios[this.index] -= diff + this.change.emit() + } } - document.addEventListener('mouseup', offHandler) + document.addEventListener('mouseup', offHandler, { passive: true }) this.element.nativeElement.parentElement.addEventListener('mousemove', dragHandler) - }) + }, { passive: true }) } ngOnChanges () { @@ -79,6 +85,13 @@ export class SplitTabSpannerComponent { } } + reset () { + const ratio = (this.container.ratios[this.index - 1] + this.container.ratios[this.index]) / 2 + this.container.ratios[this.index - 1] = ratio + this.container.ratios[this.index] = ratio + this.change.emit() + } + private setDimensions (x: number, y: number, w: number, h: number) { this.cssLeft = `${x}%` this.cssTop = `${y}%`