Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cell text selection on firefox #11

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/grid/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3036,13 +3036,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
Loading