changed spanner to emit event to splitTab and tell its mousedown state
disabled tab focus on hover when spanner is being dragged by the mouse
This commit is contained in:
Dani Nugraha 2022-12-03 13:28:07 +07:00 committed by Eugene
parent 49ccda70ea
commit 2d3234fe1d
2 changed files with 18 additions and 1 deletions

View File

@ -169,6 +169,7 @@ export type SplitDropZoneInfo = {
[container]='spanner.container'
[index]='spanner.index'
(change)='onSpannerAdjusted(spanner)'
(resizing)='onSpannerResizing($event)'
></split-tab-spanner>
<split-tab-drop-zone
*ngFor='let dropZone of _dropZones'
@ -211,6 +212,9 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
/** @hidden */
_allFocusMode = false
/** @hidden */
_spannerResizing = false
/**
* Disables display of dynamic window/tab title provided by the shell
*/
@ -737,6 +741,11 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
this.splitAdjusted.next(spanner)
}
/** @hidden */
onSpannerResizing (state: boolean): void {
this._spannerResizing = state
}
/** @hidden */
onTabDropped (tab: BaseTabComponent, zone: SplitDropZoneInfo) { // eslint-disable-line @typescript-eslint/explicit-module-boundary-types
if (tab === this) {
@ -809,7 +818,12 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
this.viewRefs.set(tab, ref)
tab.addEventListenerUntilDestroyed(ref.rootNodes[0], 'click', () => this.focus(tab))
if (this.config.store.terminal.focusFollowsMouse) {
tab.addEventListenerUntilDestroyed(ref.rootNodes[0], 'mousemove', () => this.focus(tab))
tab.addEventListenerUntilDestroyed(ref.rootNodes[0], 'mousemove', () => {
if (this._spannerResizing) {
return
}
this.focus(tab)
})
}
tab.subscribeUntilDestroyed(tab.titleChange$, () => this.updateTitle())

View File

@ -12,6 +12,7 @@ import { SplitContainer } from './splitTab.component'
export class SplitTabSpannerComponent extends SelfPositioningComponent {
@Input() container: SplitContainer
@Input() index: number
@Output() resizing = new EventEmitter<boolean>()
@Output() change = new EventEmitter<void>()
@HostBinding('class.active') isActive = false
@HostBinding('class.h') isHorizontal = false
@ -30,6 +31,7 @@ export class SplitTabSpannerComponent extends SelfPositioningComponent {
this.element.nativeElement.addEventListener('mousedown', (e: MouseEvent) => {
this.isActive = true
this.resizing.emit(true)
const start = this.isVertical ? e.pageY : e.pageX
let current = start
const oldPosition: number = this.isVertical ? this.element.nativeElement.offsetTop : this.element.nativeElement.offsetLeft
@ -46,6 +48,7 @@ export class SplitTabSpannerComponent extends SelfPositioningComponent {
const offHandler = () => {
this.isActive = false
this.resizing.emit(false)
document.removeEventListener('mouseup', offHandler)
this.element.nativeElement.parentElement.removeEventListener('mousemove', dragHandler)