Skip to content

Commit

Permalink
Fix for auto resize column headers, (microsoft#10909)
Browse files Browse the repository at this point in the history
* Fixed scroll to top

* removed brackets

* Don't trigger the cellSelectionModel when className is the resizable handler

* Added message for header listener

Co-authored-by: Amir Omidi <amomidi@microsoft.com>
  • Loading branch information
smartguest and Amir Omidi authored Jun 17, 2020
1 parent 77ba5a3 commit 95107f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const defaults: ICellSelectionModelOptions = {
selectActiveCell: true
};

interface EventTargetWithClassName extends EventTarget {
className: string | undefined;
}

export class CellSelectionModel<T> implements Slick.SelectionModel<T, Array<Slick.Range>> {
private grid!: Slick.Grid<T>;
private selector: ICellRangeSelector<T>;
Expand Down Expand Up @@ -110,6 +114,9 @@ export class CellSelectionModel<T> implements Slick.SelectionModel<T, Array<Slic
}

private handleHeaderClick(e: MouseEvent, args: Slick.OnHeaderClickEventArgs<T>) {
if ((e.target as EventTargetWithClassName).className === 'slick-resizable-handle') {
return;
}
if (!isUndefinedOrNull(args.column)) {
let columnIndex = this.grid.getColumnIndex(args.column.id!);
if (this.grid.canCellBeSelected(0, columnIndex)) {
Expand Down
7 changes: 7 additions & 0 deletions src/sql/workbench/contrib/query/browser/gridPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
this.table.registerPlugin(new AdditionalKeyBindings());
this._register(this.table.onContextMenu(this.contextMenu, this));
this._register(this.table.onClick(this.onTableClick, this));
//This listener is used for correcting auto-scroling when clicking on the header for reszing.
this._register(this.table.onHeaderClick(this.onHeaderClick, this));

if (this.styles) {
this.table.style(this.styles);
Expand Down Expand Up @@ -580,6 +582,11 @@ export abstract class GridTableBase<T> extends Disposable implements IView {
this._state = val;
}

private onHeaderClick(event: ITableMouseEvent) {
//header clicks must be accounted for as they force the table to scroll to the top;
this.scrolled = false;
}

private onTableClick(event: ITableMouseEvent) {
// account for not having the number column
let column = this.resultSet.columnInfo[event.cell.cell - 1];
Expand Down

0 comments on commit 95107f1

Please sign in to comment.