Skip to content

Commit

Permalink
Merge pull request #11 from serenity-is/fix-ff-texthighlight
Browse files Browse the repository at this point in the history
fix cell text selection on firefox
  • Loading branch information
volkanceylan authored Jul 11, 2024
2 parents 91e571b + b7d5f85 commit 52979e0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/grid/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3065,13 +3065,35 @@ export class Grid<TItem = any> implements EditorHost {
}
}

private getTextSelection(){
var selection = null;

if (window.getSelection && window.getSelection().rangeCount > 0) {
selection = window.getSelection().getRangeAt(0);
}

return selection;
}

private setTextSelection(selection: Range){
if (window.getSelection && selection) {
var target = window.getSelection();
target.removeAllRanges();
target.addRange(selection);
}
}

private handleClick(e: MouseEvent): void {
if (!this._currentEditor) {
// if this click resulted in some cell child node getting focus,
// don't steal it back - keyboard events will still bubble up
// IE9+ seems to default DIVs to tabIndex=0 instead of -1, so check for cell clicks directly.
if (e.target != document.activeElement || (e.target as HTMLElement)?.classList?.contains?.("slick-cell")) {
var selection = this.getTextSelection();
this.setFocus();
if (selection && this._options.enableTextSelectionOnCells) {
this.setTextSelection(selection);
}
}
}

Expand Down

0 comments on commit 52979e0

Please sign in to comment.