提交 19994c6a 编写于 作者: T Tiago Ribeiro 提交者: Alex Dima

Implement fast scrolling (#24344)

上级 1e2d8eda
......@@ -188,4 +188,4 @@ export class StandardWheelEvent {
}
}
}
}
\ No newline at end of file
}
......@@ -281,6 +281,7 @@ export abstract class AbstractScrollableElement extends Widget {
let massagedOptions = resolveOptions(newOptions);
this._options.handleMouseWheel = massagedOptions.handleMouseWheel;
this._options.mouseWheelScrollSensitivity = massagedOptions.mouseWheelScrollSensitivity;
this._options.fastScrollSensitivity = massagedOptions.fastScrollSensitivity;
this._setListeningToMouseWheel(this._options.handleMouseWheel);
if (!this._options.lazyRender) {
......@@ -340,6 +341,14 @@ export abstract class AbstractScrollableElement extends Widget {
deltaY = 0;
}
if (e.browserEvent.shiftKey !== null) {
//fastScrolling
if (e.browserEvent.shiftKey) {
deltaX = deltaX * this._options.fastScrollSensitivity;
deltaY = deltaY * this._options.fastScrollSensitivity;
}
}
const futureScrollPosition = this._scrollable.getFutureScrollPosition();
let desiredScrollPosition: INewScrollPosition = {};
......@@ -540,6 +549,7 @@ function resolveOptions(opts: ScrollableElementCreationOptions): ScrollableEleme
alwaysConsumeMouseWheel: (typeof opts.alwaysConsumeMouseWheel !== 'undefined' ? opts.alwaysConsumeMouseWheel : false),
scrollYToX: (typeof opts.scrollYToX !== 'undefined' ? opts.scrollYToX : false),
mouseWheelScrollSensitivity: (typeof opts.mouseWheelScrollSensitivity !== 'undefined' ? opts.mouseWheelScrollSensitivity : 1),
fastScrollSensitivity: (typeof opts.fastScrollSensitivity !== 'undefined' ? opts.fastScrollSensitivity : 5),
mouseWheelSmoothScroll: (typeof opts.mouseWheelSmoothScroll !== 'undefined' ? opts.mouseWheelSmoothScroll : true),
arrowSize: (typeof opts.arrowSize !== 'undefined' ? opts.arrowSize : 11),
......
......@@ -50,6 +50,11 @@ export interface ScrollableElementCreationOptions {
* Defaults to 1.
*/
mouseWheelScrollSensitivity?: number;
/**
* FastScrolling mulitplier speed when pressing `Shift`
* Defaults to 10.
*/
fastScrollSensitivity?: number;
/**
* Height for vertical arrows (top/bottom) and width for horizontal arrows (left/right).
* Defaults to 11.
......@@ -107,6 +112,7 @@ export interface ScrollableElementCreationOptions {
export interface ScrollableElementChangeOptions {
handleMouseWheel?: boolean;
mouseWheelScrollSensitivity?: number;
fastScrollSensitivity: number;
}
export interface ScrollableElementResolvedOptions {
......@@ -118,6 +124,7 @@ export interface ScrollableElementResolvedOptions {
scrollYToX: boolean;
alwaysConsumeMouseWheel: boolean;
mouseWheelScrollSensitivity: number;
fastScrollSensitivity: number;
mouseWheelSmoothScroll: boolean;
arrowSize: number;
listenOnDomNode: HTMLElement | null;
......
......@@ -48,6 +48,7 @@ export class EditorScrollbar extends ViewPart {
handleMouseWheel: configScrollbarOpts.handleMouseWheel,
arrowSize: configScrollbarOpts.arrowSize,
mouseWheelScrollSensitivity: configScrollbarOpts.mouseWheelScrollSensitivity,
fastScrollSensitivity: configScrollbarOpts.fastScrollSensitivity,
};
this.scrollbar = this._register(new SmoothScrollableElement(linesContent.domNode, scrollbarOptions, this._context.viewLayout.scrollable));
......@@ -127,7 +128,8 @@ export class EditorScrollbar extends ViewPart {
const editor = this._context.configuration.editor;
let newOpts: ScrollableElementChangeOptions = {
handleMouseWheel: editor.viewInfo.scrollbar.handleMouseWheel,
mouseWheelScrollSensitivity: editor.viewInfo.scrollbar.mouseWheelScrollSensitivity
mouseWheelScrollSensitivity: editor.viewInfo.scrollbar.mouseWheelScrollSensitivity,
fastScrollSensitivity: editor.viewInfo.scrollbar.fastScrollSensitivity
};
this.scrollbar.updateOptions(newOpts);
}
......
......@@ -429,6 +429,17 @@ const editorConfiguration: IConfigurationNode = {
'default': EDITOR_DEFAULTS.viewInfo.scrollbar.mouseWheelScrollSensitivity,
'markdownDescription': nls.localize('mouseWheelScrollSensitivity', "A multiplier to be used on the `deltaX` and `deltaY` of mouse wheel scroll events.")
},
'editor.fastScrollSensitivity': {
'type': 'number',
'enum': [1, 5, 10],
enumDescriptions: [
nls.localize('fastScrollSensitivity.1', "Fast Scrolling Off"),
nls.localize('fastScrollSensitivity.5', "Default Speed"),
nls.localize('fastScrollSensitivity.10', "Fast Speed"),
],
'default': EDITOR_DEFAULTS.viewInfo.scrollbar.fastScrollSensitivity,
'markdownDescription': nls.localize('fastScrollSensitivity', "Scrolling speed mulitiplier when pressing `Shift`")
},
'editor.multiCursorModifier': {
'type': 'string',
'enum': ['ctrlCmd', 'alt'],
......
......@@ -453,6 +453,11 @@ export interface IEditorOptions {
* Defaults to 1.
*/
mouseWheelScrollSensitivity?: number;
/**
* FastScrolling mulitplier speed when pressing `Shift`
* Defaults to 10.
*/
fastScrollSensitivity?: number;
/**
* The modifier to be used to add multiple cursors with the mouse.
* Defaults to 'alt'
......@@ -870,6 +875,7 @@ export interface InternalEditorScrollbarOptions {
readonly verticalScrollbarSize: number;
readonly verticalSliderSize: number;
readonly mouseWheelScrollSensitivity: number;
readonly fastScrollSensitivity: number;
}
export interface InternalEditorMinimapOptions {
......@@ -1286,6 +1292,7 @@ export class InternalEditorOptions {
&& a.verticalScrollbarSize === b.verticalScrollbarSize
&& a.verticalSliderSize === b.verticalSliderSize
&& a.mouseWheelScrollSensitivity === b.mouseWheelScrollSensitivity
&& a.fastScrollSensitivity === b.fastScrollSensitivity
);
}
......@@ -1788,7 +1795,7 @@ export class EditorOptionsValidator {
};
}
private static _sanitizeScrollbarOpts(opts: IEditorScrollbarOptions | undefined, defaults: InternalEditorScrollbarOptions, mouseWheelScrollSensitivity: number): InternalEditorScrollbarOptions {
private static _sanitizeScrollbarOpts(opts: IEditorScrollbarOptions | undefined, defaults: InternalEditorScrollbarOptions, mouseWheelScrollSensitivity: number, fastScrollSensitivity: number): InternalEditorScrollbarOptions {
if (typeof opts !== 'object') {
return defaults;
}
......@@ -1811,7 +1818,8 @@ export class EditorOptionsValidator {
verticalSliderSize: _clampedInt(opts.verticalSliderSize, verticalScrollbarSize, 0, 1000),
handleMouseWheel: _boolean(opts.handleMouseWheel, defaults.handleMouseWheel),
mouseWheelScrollSensitivity: mouseWheelScrollSensitivity
mouseWheelScrollSensitivity: mouseWheelScrollSensitivity,
fastScrollSensitivity: fastScrollSensitivity,
};
}
......@@ -1957,7 +1965,12 @@ export class EditorOptionsValidator {
// Disallow 0, as it would prevent/block scrolling
mouseWheelScrollSensitivity = 1;
}
const scrollbar = this._sanitizeScrollbarOpts(opts.scrollbar, defaults.scrollbar, mouseWheelScrollSensitivity);
let fastScrollSensitivity = _float(opts.fastScrollSensitivity, defaults.scrollbar.fastScrollSensitivity);
if (fastScrollSensitivity <= 0) {
fastScrollSensitivity = 5;
}
const scrollbar = this._sanitizeScrollbarOpts(opts.scrollbar, defaults.scrollbar, mouseWheelScrollSensitivity, fastScrollSensitivity);
const minimap = this._sanitizeMinimapOpts(opts.minimap, defaults.minimap);
return {
......@@ -2584,6 +2597,7 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
verticalSliderSize: 14,
handleMouseWheel: true,
mouseWheelScrollSensitivity: 1,
fastScrollSensitivity: 5,
},
minimap: {
enabled: true,
......
......@@ -2805,6 +2805,11 @@ declare namespace monaco.editor {
* Defaults to 1.
*/
mouseWheelScrollSensitivity?: number;
/**
* FastScrolling mulitplier speed when pressing `Shift`
* Defaults to 10.
*/
fastScrollSensitivity?: number;
/**
* The modifier to be used to add multiple cursors with the mouse.
* Defaults to 'alt'
......@@ -3167,6 +3172,7 @@ declare namespace monaco.editor {
readonly verticalScrollbarSize: number;
readonly verticalSliderSize: number;
readonly mouseWheelScrollSensitivity: number;
readonly fastScrollSensitivity: number;
}
export interface InternalEditorMinimapOptions {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册