Skip to content

Selectable Fast Scroll Key #78555

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/vs/base/browser/ui/scrollbar/scrollableElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export abstract class AbstractScrollableElement extends Widget {
this._options.handleMouseWheel = massagedOptions.handleMouseWheel;
this._options.mouseWheelScrollSensitivity = massagedOptions.mouseWheelScrollSensitivity;
this._options.fastScrollSensitivity = massagedOptions.fastScrollSensitivity;
this._options.fastScrollKey = massagedOptions.fastScrollKey;
this._setListeningToMouseWheel(this._options.handleMouseWheel);

if (!this._options.lazyRender) {
Expand Down Expand Up @@ -346,12 +347,16 @@ export abstract class AbstractScrollableElement extends Widget {
deltaY = 0;
}

if (e.browserEvent && e.browserEvent.altKey) {

if (e.browserEvent && ((this._options.fastScrollKey === 'alt' && e.browserEvent.altKey)
|| (this._options.fastScrollKey === 'ctrl' && e.browserEvent.ctrlKey)
|| (this._options.fastScrollKey === 'shift' && e.browserEvent.shiftKey))) {
// fastScrolling
deltaX = deltaX * this._options.fastScrollSensitivity;
deltaY = deltaY * this._options.fastScrollSensitivity;
}


const futureScrollPosition = this._scrollable.getFutureScrollPosition();

let desiredScrollPosition: INewScrollPosition = {};
Expand Down Expand Up @@ -553,6 +558,7 @@ function resolveOptions(opts: ScrollableElementCreationOptions): ScrollableEleme
scrollYToX: (typeof opts.scrollYToX !== 'undefined' ? opts.scrollYToX : false),
mouseWheelScrollSensitivity: (typeof opts.mouseWheelScrollSensitivity !== 'undefined' ? opts.mouseWheelScrollSensitivity : 1),
fastScrollSensitivity: (typeof opts.fastScrollSensitivity !== 'undefined' ? opts.fastScrollSensitivity : 5),
fastScrollKey: (typeof opts.fastScrollKey !== 'undefined' ? opts.fastScrollKey : 'alt'),
mouseWheelSmoothScroll: (typeof opts.mouseWheelSmoothScroll !== 'undefined' ? opts.mouseWheelSmoothScroll : true),
arrowSize: (typeof opts.arrowSize !== 'undefined' ? opts.arrowSize : 11),

Expand Down
7 changes: 7 additions & 0 deletions src/vs/base/browser/ui/scrollbar/scrollableElementOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export interface ScrollableElementCreationOptions {
* Defaults to 5.
*/
fastScrollSensitivity?: number;
/**
* FastScrolling key
* Defaults to 'Alt'.
*/
fastScrollKey?: string | undefined;
/**
* Height for vertical arrows (top/bottom) and width for horizontal arrows (left/right).
* Defaults to 11.
Expand Down Expand Up @@ -113,6 +118,7 @@ export interface ScrollableElementChangeOptions {
handleMouseWheel?: boolean;
mouseWheelScrollSensitivity?: number;
fastScrollSensitivity: number;
fastScrollKey: string | undefined;
}

export interface ScrollableElementResolvedOptions {
Expand All @@ -125,6 +131,7 @@ export interface ScrollableElementResolvedOptions {
alwaysConsumeMouseWheel: boolean;
mouseWheelScrollSensitivity: number;
fastScrollSensitivity: number;
fastScrollKey: string | undefined;
mouseWheelSmoothScroll: boolean;
arrowSize: number;
listenOnDomNode: HTMLElement | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class EditorScrollbar extends ViewPart {
const scrollbar = options.get(EditorOption.scrollbar);
const mouseWheelScrollSensitivity = options.get(EditorOption.mouseWheelScrollSensitivity);
const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity);
const fastScrollKey = options.get(EditorOption.fastScrollKey);

const scrollbarOptions: ScrollableElementCreationOptions = {
listenOnDomNode: viewDomNode.domNode,
Expand All @@ -53,6 +54,7 @@ export class EditorScrollbar extends ViewPart {
arrowSize: scrollbar.arrowSize,
mouseWheelScrollSensitivity: mouseWheelScrollSensitivity,
fastScrollSensitivity: fastScrollSensitivity,
fastScrollKey: fastScrollKey,
};

this.scrollbar = this._register(new SmoothScrollableElement(linesContent.domNode, scrollbarOptions, this._context.viewLayout.scrollable));
Expand Down Expand Up @@ -139,10 +141,12 @@ export class EditorScrollbar extends ViewPart {
const scrollbar = options.get(EditorOption.scrollbar);
const mouseWheelScrollSensitivity = options.get(EditorOption.mouseWheelScrollSensitivity);
const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity);
const fastScrollKey = options.get(EditorOption.fastScrollKey);
const newOpts: ScrollableElementChangeOptions = {
handleMouseWheel: scrollbar.handleMouseWheel,
mouseWheelScrollSensitivity: mouseWheelScrollSensitivity,
fastScrollSensitivity: fastScrollSensitivity
fastScrollSensitivity: fastScrollSensitivity,
fastScrollKey: fastScrollKey
};
this.scrollbar.updateOptions(newOpts);
}
Expand Down
12 changes: 12 additions & 0 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ export interface IEditorOptions {
* Defaults to 5.
*/
fastScrollSensitivity?: number;
/**
* FastScrolling key
* Defaults to 'Alt'.
*/
fastScrollKey?: 'ctrl' | 'alt' | 'shift';
/**
* The modifier to be used to add multiple cursors with the mouse.
* Defaults to 'alt'
Expand Down Expand Up @@ -2639,6 +2644,7 @@ export const enum EditorOption {
dragAndDrop,
emptySelectionClipboard,
extraEditorClassName,
fastScrollKey,
fastScrollSensitivity,
find,
fixedOverflowWidgets,
Expand Down Expand Up @@ -2865,6 +2871,12 @@ export const EditorOptions = {
extraEditorClassName: register(new EditorStringOption(
EditorOption.extraEditorClassName, 'extraEditorClassName', '',
)),
fastScrollKey: register(new EditorStringEnumOption(
EditorOption.fastScrollKey, 'fastScrollKey',
'alt' as 'ctrl' | 'alt' | 'shift',
['ctrl', 'alt', 'shift'] as const,
{ markdownDescription: nls.localize('fastScrollKey', "Key that activates `Fast Scroll` when pressed") }
)),
fastScrollSensitivity: register(new EditorFloatOption(
EditorOption.fastScrollSensitivity, 'fastScrollSensitivity',
5, x => (x <= 0 ? 5 : x),
Expand Down
5 changes: 5 additions & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,11 @@ declare namespace monaco.editor {
* Defaults to 5.
*/
fastScrollSensitivity?: number;
/**
* FastScrolling key
* Defaults to 'Alt'.
*/
fastScrollKey?: 'ctrl' | 'alt' | 'shift';
/**
* The modifier to be used to add multiple cursors with the mouse.
* Defaults to 'alt'
Expand Down