Skip to content

Commit 1bf0aea

Browse files
authored
Merge pull request microsoft#70047 from gubikmic/scrollPredominantAxisOnly
Scroll predominant axis only (prevents scroll drift)
2 parents 9dd1ee4 + ee61306 commit 1bf0aea

File tree

6 files changed

+98
-57
lines changed

6 files changed

+98
-57
lines changed

src/vs/base/browser/ui/scrollbar/scrollableElement.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export abstract class AbstractScrollableElement extends Widget {
287287
this._options.handleMouseWheel = massagedOptions.handleMouseWheel;
288288
this._options.mouseWheelScrollSensitivity = massagedOptions.mouseWheelScrollSensitivity;
289289
this._options.fastScrollSensitivity = massagedOptions.fastScrollSensitivity;
290+
this._options.scrollPredominantAxis = massagedOptions.scrollPredominantAxis;
290291
this._setListeningToMouseWheel(this._options.handleMouseWheel);
291292

292293
if (!this._options.lazyRender) {
@@ -334,6 +335,14 @@ export abstract class AbstractScrollableElement extends Widget {
334335
let deltaY = e.deltaY * this._options.mouseWheelScrollSensitivity;
335336
let deltaX = e.deltaX * this._options.mouseWheelScrollSensitivity;
336337

338+
if (this._options.scrollPredominantAxis) {
339+
if (Math.abs(deltaY) >= Math.abs(deltaX)) {
340+
deltaX = 0;
341+
} else {
342+
deltaY = 0;
343+
}
344+
}
345+
337346
if (this._options.flipAxes) {
338347
[deltaY, deltaX] = [deltaX, deltaY];
339348
}
@@ -553,6 +562,7 @@ function resolveOptions(opts: ScrollableElementCreationOptions): ScrollableEleme
553562
scrollYToX: (typeof opts.scrollYToX !== 'undefined' ? opts.scrollYToX : false),
554563
mouseWheelScrollSensitivity: (typeof opts.mouseWheelScrollSensitivity !== 'undefined' ? opts.mouseWheelScrollSensitivity : 1),
555564
fastScrollSensitivity: (typeof opts.fastScrollSensitivity !== 'undefined' ? opts.fastScrollSensitivity : 5),
565+
scrollPredominantAxis: (typeof opts.scrollPredominantAxis !== 'undefined' ? opts.scrollPredominantAxis : true),
556566
mouseWheelSmoothScroll: (typeof opts.mouseWheelSmoothScroll !== 'undefined' ? opts.mouseWheelSmoothScroll : true),
557567
arrowSize: (typeof opts.arrowSize !== 'undefined' ? opts.arrowSize : 11),
558568

src/vs/base/browser/ui/scrollbar/scrollableElementOptions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ export interface ScrollableElementCreationOptions {
5555
* Defaults to 5.
5656
*/
5757
fastScrollSensitivity?: number;
58+
/**
59+
* Whether the scrollable will only scroll along the predominant axis when scrolling both
60+
* vertically and horizontally at the same time.
61+
* Prevents horizontal drift when scrolling vertically on a trackpad.
62+
* Defaults to true.
63+
*/
64+
scrollPredominantAxis?: boolean;
5865
/**
5966
* Height for vertical arrows (top/bottom) and width for horizontal arrows (left/right).
6067
* Defaults to 11.
@@ -113,6 +120,7 @@ export interface ScrollableElementChangeOptions {
113120
handleMouseWheel?: boolean;
114121
mouseWheelScrollSensitivity?: number;
115122
fastScrollSensitivity: number;
123+
scrollPredominantAxis: boolean;
116124
}
117125

118126
export interface ScrollableElementResolvedOptions {
@@ -125,6 +133,7 @@ export interface ScrollableElementResolvedOptions {
125133
alwaysConsumeMouseWheel: boolean;
126134
mouseWheelScrollSensitivity: number;
127135
fastScrollSensitivity: number;
136+
scrollPredominantAxis: boolean;
128137
mouseWheelSmoothScroll: boolean;
129138
arrowSize: number;
130139
listenOnDomNode: HTMLElement | null;

src/vs/editor/browser/viewParts/editorScrollbar/editorScrollbar.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class EditorScrollbar extends ViewPart {
3434
const scrollbar = options.get(EditorOption.scrollbar);
3535
const mouseWheelScrollSensitivity = options.get(EditorOption.mouseWheelScrollSensitivity);
3636
const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity);
37+
const scrollPredominantAxis = options.get(EditorOption.scrollPredominantAxis);
3738

3839
const scrollbarOptions: ScrollableElementCreationOptions = {
3940
listenOnDomNode: viewDomNode.domNode,
@@ -54,6 +55,7 @@ export class EditorScrollbar extends ViewPart {
5455
arrowSize: scrollbar.arrowSize,
5556
mouseWheelScrollSensitivity: mouseWheelScrollSensitivity,
5657
fastScrollSensitivity: fastScrollSensitivity,
58+
scrollPredominantAxis: scrollPredominantAxis,
5759
};
5860

5961
this.scrollbar = this._register(new SmoothScrollableElement(linesContent.domNode, scrollbarOptions, this._context.viewLayout.getScrollable()));
@@ -140,10 +142,12 @@ export class EditorScrollbar extends ViewPart {
140142
const scrollbar = options.get(EditorOption.scrollbar);
141143
const mouseWheelScrollSensitivity = options.get(EditorOption.mouseWheelScrollSensitivity);
142144
const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity);
145+
const scrollPredominantAxis = options.get(EditorOption.scrollPredominantAxis);
143146
const newOpts: ScrollableElementChangeOptions = {
144147
handleMouseWheel: scrollbar.handleMouseWheel,
145148
mouseWheelScrollSensitivity: mouseWheelScrollSensitivity,
146-
fastScrollSensitivity: fastScrollSensitivity
149+
fastScrollSensitivity: fastScrollSensitivity,
150+
scrollPredominantAxis: scrollPredominantAxis
147151
};
148152
this.scrollbar.updateOptions(newOpts);
149153
}

src/vs/editor/common/config/editorOptions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ export interface IEditorOptions {
319319
* Defaults to 5.
320320
*/
321321
fastScrollSensitivity?: number;
322+
/**
323+
* Enable that the editor scrolls only the predominant axis. Prevents horizontal drift when scrolling vertically on a trackpad.
324+
* Defaults to true.
325+
*/
326+
scrollPredominantAxis?: boolean;
322327
/**
323328
* The modifier to be used to add multiple cursors with the mouse.
324329
* Defaults to 'alt'
@@ -3193,6 +3198,7 @@ export const enum EditorOption {
31933198
scrollbar,
31943199
scrollBeyondLastColumn,
31953200
scrollBeyondLastLine,
3201+
scrollPredominantAxis,
31963202
selectionClipboard,
31973203
selectionHighlight,
31983204
selectOnLineNumbers,
@@ -3651,6 +3657,10 @@ export const EditorOptions = {
36513657
EditorOption.scrollBeyondLastLine, 'scrollBeyondLastLine', true,
36523658
{ description: nls.localize('scrollBeyondLastLine', "Controls whether the editor will scroll beyond the last line.") }
36533659
)),
3660+
scrollPredominantAxis: register(new EditorBooleanOption(
3661+
EditorOption.scrollPredominantAxis, 'scrollPredominantAxis', true,
3662+
{ description: nls.localize('scrollPredominantAxis', "Scroll only along the predominant axis when scrolling both vertically and horizontally at the same time. Prevents horizontal drift when scrolling vertically on a trackpad.") }
3663+
)),
36543664
selectionClipboard: register(new EditorBooleanOption(
36553665
EditorOption.selectionClipboard, 'selectionClipboard', true,
36563666
{

src/vs/editor/common/standalone/standaloneEnums.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -247,34 +247,35 @@ export enum EditorOption {
247247
scrollbar = 79,
248248
scrollBeyondLastColumn = 80,
249249
scrollBeyondLastLine = 81,
250-
selectionClipboard = 82,
251-
selectionHighlight = 83,
252-
selectOnLineNumbers = 84,
253-
showFoldingControls = 85,
254-
showUnused = 86,
255-
snippetSuggestions = 87,
256-
smoothScrolling = 88,
257-
stopRenderingLineAfter = 89,
258-
suggest = 90,
259-
suggestFontSize = 91,
260-
suggestLineHeight = 92,
261-
suggestOnTriggerCharacters = 93,
262-
suggestSelection = 94,
263-
tabCompletion = 95,
264-
useTabStops = 96,
265-
wordSeparators = 97,
266-
wordWrap = 98,
267-
wordWrapBreakAfterCharacters = 99,
268-
wordWrapBreakBeforeCharacters = 100,
269-
wordWrapColumn = 101,
270-
wordWrapMinified = 102,
271-
wrappingIndent = 103,
272-
wrappingStrategy = 104,
273-
editorClassName = 105,
274-
pixelRatio = 106,
275-
tabFocusMode = 107,
276-
layoutInfo = 108,
277-
wrappingInfo = 109
250+
scrollPredominantAxis = 82,
251+
selectionClipboard = 83,
252+
selectionHighlight = 84,
253+
selectOnLineNumbers = 85,
254+
showFoldingControls = 86,
255+
showUnused = 87,
256+
snippetSuggestions = 88,
257+
smoothScrolling = 89,
258+
stopRenderingLineAfter = 90,
259+
suggest = 91,
260+
suggestFontSize = 92,
261+
suggestLineHeight = 93,
262+
suggestOnTriggerCharacters = 94,
263+
suggestSelection = 95,
264+
tabCompletion = 96,
265+
useTabStops = 97,
266+
wordSeparators = 98,
267+
wordWrap = 99,
268+
wordWrapBreakAfterCharacters = 100,
269+
wordWrapBreakBeforeCharacters = 101,
270+
wordWrapColumn = 102,
271+
wordWrapMinified = 103,
272+
wrappingIndent = 104,
273+
wrappingStrategy = 105,
274+
editorClassName = 106,
275+
pixelRatio = 107,
276+
tabFocusMode = 108,
277+
layoutInfo = 109,
278+
wrappingInfo = 110
278279
}
279280

280281
/**

src/vs/monaco.d.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,11 @@ declare namespace monaco.editor {
27942794
* Defaults to 5.
27952795
*/
27962796
fastScrollSensitivity?: number;
2797+
/**
2798+
* Enable that the editor scrolls only the predominant axis. Prevents horizontal drift when scrolling vertically on a trackpad.
2799+
* Defaults to true.
2800+
*/
2801+
scrollPredominantAxis?: boolean;
27972802
/**
27982803
* The modifier to be used to add multiple cursors with the mouse.
27992804
* Defaults to 'alt'
@@ -3772,34 +3777,35 @@ declare namespace monaco.editor {
37723777
scrollbar = 79,
37733778
scrollBeyondLastColumn = 80,
37743779
scrollBeyondLastLine = 81,
3775-
selectionClipboard = 82,
3776-
selectionHighlight = 83,
3777-
selectOnLineNumbers = 84,
3778-
showFoldingControls = 85,
3779-
showUnused = 86,
3780-
snippetSuggestions = 87,
3781-
smoothScrolling = 88,
3782-
stopRenderingLineAfter = 89,
3783-
suggest = 90,
3784-
suggestFontSize = 91,
3785-
suggestLineHeight = 92,
3786-
suggestOnTriggerCharacters = 93,
3787-
suggestSelection = 94,
3788-
tabCompletion = 95,
3789-
useTabStops = 96,
3790-
wordSeparators = 97,
3791-
wordWrap = 98,
3792-
wordWrapBreakAfterCharacters = 99,
3793-
wordWrapBreakBeforeCharacters = 100,
3794-
wordWrapColumn = 101,
3795-
wordWrapMinified = 102,
3796-
wrappingIndent = 103,
3797-
wrappingStrategy = 104,
3798-
editorClassName = 105,
3799-
pixelRatio = 106,
3800-
tabFocusMode = 107,
3801-
layoutInfo = 108,
3802-
wrappingInfo = 109
3780+
scrollPredominantAxis = 82,
3781+
selectionClipboard = 83,
3782+
selectionHighlight = 84,
3783+
selectOnLineNumbers = 85,
3784+
showFoldingControls = 86,
3785+
showUnused = 87,
3786+
snippetSuggestions = 88,
3787+
smoothScrolling = 89,
3788+
stopRenderingLineAfter = 90,
3789+
suggest = 91,
3790+
suggestFontSize = 92,
3791+
suggestLineHeight = 93,
3792+
suggestOnTriggerCharacters = 94,
3793+
suggestSelection = 95,
3794+
tabCompletion = 96,
3795+
useTabStops = 97,
3796+
wordSeparators = 98,
3797+
wordWrap = 99,
3798+
wordWrapBreakAfterCharacters = 100,
3799+
wordWrapBreakBeforeCharacters = 101,
3800+
wordWrapColumn = 102,
3801+
wordWrapMinified = 103,
3802+
wrappingIndent = 104,
3803+
wrappingStrategy = 105,
3804+
editorClassName = 106,
3805+
pixelRatio = 107,
3806+
tabFocusMode = 108,
3807+
layoutInfo = 109,
3808+
wrappingInfo = 110
38033809
}
38043810
export const EditorOptions: {
38053811
acceptSuggestionOnCommitCharacter: IEditorOption<EditorOption.acceptSuggestionOnCommitCharacter, boolean>;
@@ -3884,6 +3890,7 @@ declare namespace monaco.editor {
38843890
scrollbar: IEditorOption<EditorOption.scrollbar, InternalEditorScrollbarOptions>;
38853891
scrollBeyondLastColumn: IEditorOption<EditorOption.scrollBeyondLastColumn, number>;
38863892
scrollBeyondLastLine: IEditorOption<EditorOption.scrollBeyondLastLine, boolean>;
3893+
scrollPredominantAxis: IEditorOption<EditorOption.scrollPredominantAxis, boolean>;
38873894
selectionClipboard: IEditorOption<EditorOption.selectionClipboard, boolean>;
38883895
selectionHighlight: IEditorOption<EditorOption.selectionHighlight, boolean>;
38893896
selectOnLineNumbers: IEditorOption<EditorOption.selectOnLineNumbers, boolean>;

0 commit comments

Comments
 (0)