mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Account for Horizontal Scrolling in Grid (#2774)
* implement horizontal scroll login in the grid plugin * remove commented code * formatting
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import * as DOM from 'vs/base/browser/dom';
|
import * as DOM from 'vs/base/browser/dom';
|
||||||
|
import * as Platform from 'vs/base/common/platform';
|
||||||
import { StandardMouseWheelEvent } from 'vs/base/browser/mouseEvent';
|
import { StandardMouseWheelEvent } from 'vs/base/browser/mouseEvent';
|
||||||
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
||||||
import { mixin } from 'vs/base/common/objects';
|
import { mixin } from 'vs/base/common/objects';
|
||||||
@@ -29,7 +30,7 @@ export class MouseWheelSupport implements Slick.Plugin<any> {
|
|||||||
private _disposables: IDisposable[] = [];
|
private _disposables: IDisposable[] = [];
|
||||||
|
|
||||||
constructor(options: IMouseWheelSupportOptions = {}) {
|
constructor(options: IMouseWheelSupportOptions = {}) {
|
||||||
this.options = mixin(options, defaultOptions);
|
this.options = mixin(options, defaultOptions, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(grid: Slick.Grid<any>): void {
|
public init(grid: Slick.Grid<any>): void {
|
||||||
@@ -43,31 +44,71 @@ export class MouseWheelSupport implements Slick.Plugin<any> {
|
|||||||
this._disposables.push(DOM.addDisposableListener(this.viewport, 'DOMMouseScroll', onMouseWheel));
|
this._disposables.push(DOM.addDisposableListener(this.viewport, 'DOMMouseScroll', onMouseWheel));
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onMouseWheel(event: StandardMouseWheelEvent) {
|
private _onMouseWheel(e: StandardMouseWheelEvent) {
|
||||||
|
if (e.deltaY || e.deltaX) {
|
||||||
|
let deltaY = e.deltaY * this.options.scrollSpeed;
|
||||||
|
let deltaX = e.deltaX * this.options.scrollSpeed;
|
||||||
const scrollHeight = this.canvas.clientHeight;
|
const scrollHeight = this.canvas.clientHeight;
|
||||||
|
const scrollWidth = this.canvas.clientWidth;
|
||||||
const height = this.viewport.clientHeight;
|
const height = this.viewport.clientHeight;
|
||||||
const scrollDown = Math.sign(event.deltaY) === -1;
|
const width = this.viewport.clientWidth;
|
||||||
if (scrollDown) {
|
|
||||||
if ((this.viewport.scrollTop - (event.deltaY * this.options.scrollSpeed)) + height > scrollHeight) {
|
// Convert vertical scrolling to horizontal if shift is held, this
|
||||||
|
// is handled at a higher level on Mac
|
||||||
|
const shiftConvert = !Platform.isMacintosh && e.browserEvent && e.browserEvent.shiftKey;
|
||||||
|
if (shiftConvert && !deltaX) {
|
||||||
|
deltaX = deltaY;
|
||||||
|
deltaY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// scroll down
|
||||||
|
if (deltaY < 0) {
|
||||||
|
if ((this.viewport.scrollTop - deltaY) + height > scrollHeight) {
|
||||||
this.viewport.scrollTop = scrollHeight - height;
|
this.viewport.scrollTop = scrollHeight - height;
|
||||||
this.viewport.dispatchEvent(new Event('scroll'));
|
this.viewport.dispatchEvent(new Event('scroll'));
|
||||||
} else {
|
} else {
|
||||||
this.viewport.scrollTop = this.viewport.scrollTop - (event.deltaY * this.options.scrollSpeed);
|
this.viewport.scrollTop = this.viewport.scrollTop - deltaY;
|
||||||
this.viewport.dispatchEvent(new Event('scroll'));
|
this.viewport.dispatchEvent(new Event('scroll'));
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
// scroll up
|
||||||
} else {
|
} else {
|
||||||
if ((this.viewport.scrollTop - (event.deltaY * this.options.scrollSpeed)) < 0) {
|
if ((this.viewport.scrollTop - deltaY) < 0) {
|
||||||
this.viewport.scrollTop = 0;
|
this.viewport.scrollTop = 0;
|
||||||
this.viewport.dispatchEvent(new Event('scroll'));
|
this.viewport.dispatchEvent(new Event('scroll'));
|
||||||
} else {
|
} else {
|
||||||
this.viewport.scrollTop = this.viewport.scrollTop - (event.deltaY * this.options.scrollSpeed);
|
this.viewport.scrollTop = this.viewport.scrollTop - deltaY;
|
||||||
this.viewport.dispatchEvent(new Event('scroll'));
|
this.viewport.dispatchEvent(new Event('scroll'));
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// scroll left
|
||||||
|
if (deltaX < 0) {
|
||||||
|
if ((this.viewport.scrollLeft - deltaX) + width > scrollWidth) {
|
||||||
|
this.viewport.scrollLeft = scrollWidth - width;
|
||||||
|
this.viewport.dispatchEvent(new Event('scroll'));
|
||||||
|
} else {
|
||||||
|
this.viewport.scrollLeft = this.viewport.scrollLeft - deltaX;
|
||||||
|
this.viewport.dispatchEvent(new Event('scroll'));
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
// scroll left
|
||||||
|
} else {
|
||||||
|
if ((this.viewport.scrollLeft - deltaX) < 0) {
|
||||||
|
this.viewport.scrollLeft = 0;
|
||||||
|
this.viewport.dispatchEvent(new Event('scroll'));
|
||||||
|
} else {
|
||||||
|
this.viewport.scrollLeft = this.viewport.scrollLeft - deltaX;
|
||||||
|
this.viewport.dispatchEvent(new Event('scroll'));
|
||||||
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
|||||||
Reference in New Issue
Block a user