Skip to content

Commit 5fc3aa9

Browse files
committed
fix: force gutter events cancellation when inputs change affects sizes
1 parent 45db74b commit 5fc3aa9

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

projects/angular-split/src/lib/split-custom-events-behavior.directive.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
filter,
66
fromEvent,
77
map,
8+
merge,
89
mergeMap,
910
of,
1011
repeat,
@@ -17,6 +18,7 @@ import {
1718
} from 'rxjs'
1819
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'
1920
import { DOCUMENT } from '@angular/common'
21+
import { SplitComponent } from './split/split.component'
2022

2123
/**
2224
* Emits mousedown, click, double click and keydown out of zone
@@ -31,6 +33,7 @@ import { DOCUMENT } from '@angular/common'
3133
standalone: true,
3234
})
3335
export class SplitCustomEventsBehaviorDirective {
36+
private readonly split = inject(SplitComponent)
3437
private readonly elementRef = inject<ElementRef<HTMLElement>>(ElementRef)
3538
private readonly document = inject(DOCUMENT)
3639

@@ -84,8 +87,8 @@ export class SplitCustomEventsBehaviorDirective {
8487
),
8588
),
8689
),
87-
// Discard everything once drag started and listen again (repeat) to mouse down
88-
takeUntil(dragStarted$),
90+
// Discard everything once drag started or force cancel and listen again (repeat) to mouse down
91+
takeUntil(merge(dragStarted$, this.split._forceCancelGutterEvents$)),
8992
repeat(),
9093
leaveNgZone(),
9194
takeUntilDestroyed(),

projects/angular-split/src/lib/split/split.component.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@ import {
1818
} from '@angular/core'
1919
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'
2020
import { SplitAreaComponent } from '../split-area/split-area.component'
21-
import { Subject, filter, fromEvent, map, pairwise, skipWhile, startWith, switchMap, take, takeUntil, tap } from 'rxjs'
21+
import {
22+
Subject,
23+
filter,
24+
fromEvent,
25+
map,
26+
pairwise,
27+
repeat,
28+
skipWhile,
29+
startWith,
30+
switchMap,
31+
take,
32+
takeUntil,
33+
tap,
34+
} from 'rxjs'
2235
import {
2336
ClientPoint,
2437
createClassesString,
@@ -76,6 +89,10 @@ export class SplitComponent {
7689
private readonly ngZone = inject(NgZone)
7790
private readonly defaultOptions = inject(ANGULAR_SPLIT_DEFAULT_OPTIONS)
7891

92+
/**
93+
* @internal
94+
*/
95+
readonly _forceCancelGutterEvents$ = new Subject<void>()
7996
private readonly gutterMouseDown$ = new Subject<MouseDownContext>()
8097
private readonly dragProgressSubject = new Subject<SplitGutterInteractionEvent>()
8198

@@ -196,6 +213,7 @@ export class SplitComponent {
196213
return
197214
}
198215

216+
this._forceCancelGutterEvents$.next()
199217
visibleAreas.forEach((area) => area._internalSize.reset())
200218

201219
const isValid = areAreasValid(visibleAreas, unit)
@@ -281,6 +299,8 @@ export class SplitComponent {
281299
),
282300
),
283301
),
302+
takeUntil(this._forceCancelGutterEvents$),
303+
repeat(),
284304
takeUntilDestroyed(),
285305
)
286306
.subscribe()

0 commit comments

Comments
 (0)