Skip to content

Commit

Permalink
fix(core): use immutable range for trigger stream in Safari (#6220)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Dec 12, 2023
1 parent 47b9998 commit ddb07f9
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export class TuiDropdownSelectionDirective
this.handler$,
this.selection$.pipe(
map(() => this.getRange()),
distinctUntilChanged(),
distinctUntilChanged(
(x, y) => x.startOffset === y.startOffset && x.endOffset === y.endOffset,
),
),
]).pipe(
map(([handler, range]) => {
Expand Down Expand Up @@ -123,12 +125,12 @@ export class TuiDropdownSelectionDirective
private getRange(): Range {
const active = tuiGetNativeFocused(this.doc);
const selection = this.doc.getSelection();
const range =
active && tuiIsTextfield(active) && this.el.nativeElement.contains(active)
? this.veryVerySadInputFix(active)
: (selection?.rangeCount && selection.getRangeAt(0)) || this.range;

if (active && tuiIsTextfield(active) && this.el.nativeElement.contains(active)) {
return this.veryVerySadInputFix(active);
}

return selection?.rangeCount ? selection.getRangeAt(0) : this.range;
return range.cloneRange();
}

/**
Expand Down

0 comments on commit ddb07f9

Please sign in to comment.