未验证 提交 1bf0aeae 编写于 作者: A Alexandru Dima 提交者: GitHub

Merge pull request #70047 from gubikmic/scrollPredominantAxisOnly

Scroll predominant axis only (prevents scroll drift)
...@@ -287,6 +287,7 @@ export abstract class AbstractScrollableElement extends Widget { ...@@ -287,6 +287,7 @@ export abstract class AbstractScrollableElement extends Widget {
this._options.handleMouseWheel = massagedOptions.handleMouseWheel; this._options.handleMouseWheel = massagedOptions.handleMouseWheel;
this._options.mouseWheelScrollSensitivity = massagedOptions.mouseWheelScrollSensitivity; this._options.mouseWheelScrollSensitivity = massagedOptions.mouseWheelScrollSensitivity;
this._options.fastScrollSensitivity = massagedOptions.fastScrollSensitivity; this._options.fastScrollSensitivity = massagedOptions.fastScrollSensitivity;
this._options.scrollPredominantAxis = massagedOptions.scrollPredominantAxis;
this._setListeningToMouseWheel(this._options.handleMouseWheel); this._setListeningToMouseWheel(this._options.handleMouseWheel);
if (!this._options.lazyRender) { if (!this._options.lazyRender) {
...@@ -334,6 +335,14 @@ export abstract class AbstractScrollableElement extends Widget { ...@@ -334,6 +335,14 @@ export abstract class AbstractScrollableElement extends Widget {
let deltaY = e.deltaY * this._options.mouseWheelScrollSensitivity; let deltaY = e.deltaY * this._options.mouseWheelScrollSensitivity;
let deltaX = e.deltaX * this._options.mouseWheelScrollSensitivity; let deltaX = e.deltaX * this._options.mouseWheelScrollSensitivity;
if (this._options.scrollPredominantAxis) {
if (Math.abs(deltaY) >= Math.abs(deltaX)) {
deltaX = 0;
} else {
deltaY = 0;
}
}
if (this._options.flipAxes) { if (this._options.flipAxes) {
[deltaY, deltaX] = [deltaX, deltaY]; [deltaY, deltaX] = [deltaX, deltaY];
} }
...@@ -553,6 +562,7 @@ function resolveOptions(opts: ScrollableElementCreationOptions): ScrollableEleme ...@@ -553,6 +562,7 @@ function resolveOptions(opts: ScrollableElementCreationOptions): ScrollableEleme
scrollYToX: (typeof opts.scrollYToX !== 'undefined' ? opts.scrollYToX : false), scrollYToX: (typeof opts.scrollYToX !== 'undefined' ? opts.scrollYToX : false),
mouseWheelScrollSensitivity: (typeof opts.mouseWheelScrollSensitivity !== 'undefined' ? opts.mouseWheelScrollSensitivity : 1), mouseWheelScrollSensitivity: (typeof opts.mouseWheelScrollSensitivity !== 'undefined' ? opts.mouseWheelScrollSensitivity : 1),
fastScrollSensitivity: (typeof opts.fastScrollSensitivity !== 'undefined' ? opts.fastScrollSensitivity : 5), fastScrollSensitivity: (typeof opts.fastScrollSensitivity !== 'undefined' ? opts.fastScrollSensitivity : 5),
scrollPredominantAxis: (typeof opts.scrollPredominantAxis !== 'undefined' ? opts.scrollPredominantAxis : true),
mouseWheelSmoothScroll: (typeof opts.mouseWheelSmoothScroll !== 'undefined' ? opts.mouseWheelSmoothScroll : true), mouseWheelSmoothScroll: (typeof opts.mouseWheelSmoothScroll !== 'undefined' ? opts.mouseWheelSmoothScroll : true),
arrowSize: (typeof opts.arrowSize !== 'undefined' ? opts.arrowSize : 11), arrowSize: (typeof opts.arrowSize !== 'undefined' ? opts.arrowSize : 11),
......
...@@ -55,6 +55,13 @@ export interface ScrollableElementCreationOptions { ...@@ -55,6 +55,13 @@ export interface ScrollableElementCreationOptions {
* Defaults to 5. * Defaults to 5.
*/ */
fastScrollSensitivity?: number; fastScrollSensitivity?: number;
/**
* Whether the scrollable will only scroll along the predominant axis when scrolling both
* vertically and horizontally at the same time.
* Prevents horizontal drift when scrolling vertically on a trackpad.
* Defaults to true.
*/
scrollPredominantAxis?: boolean;
/** /**
* Height for vertical arrows (top/bottom) and width for horizontal arrows (left/right). * Height for vertical arrows (top/bottom) and width for horizontal arrows (left/right).
* Defaults to 11. * Defaults to 11.
...@@ -113,6 +120,7 @@ export interface ScrollableElementChangeOptions { ...@@ -113,6 +120,7 @@ export interface ScrollableElementChangeOptions {
handleMouseWheel?: boolean; handleMouseWheel?: boolean;
mouseWheelScrollSensitivity?: number; mouseWheelScrollSensitivity?: number;
fastScrollSensitivity: number; fastScrollSensitivity: number;
scrollPredominantAxis: boolean;
} }
export interface ScrollableElementResolvedOptions { export interface ScrollableElementResolvedOptions {
...@@ -125,6 +133,7 @@ export interface ScrollableElementResolvedOptions { ...@@ -125,6 +133,7 @@ export interface ScrollableElementResolvedOptions {
alwaysConsumeMouseWheel: boolean; alwaysConsumeMouseWheel: boolean;
mouseWheelScrollSensitivity: number; mouseWheelScrollSensitivity: number;
fastScrollSensitivity: number; fastScrollSensitivity: number;
scrollPredominantAxis: boolean;
mouseWheelSmoothScroll: boolean; mouseWheelSmoothScroll: boolean;
arrowSize: number; arrowSize: number;
listenOnDomNode: HTMLElement | null; listenOnDomNode: HTMLElement | null;
......
...@@ -34,6 +34,7 @@ export class EditorScrollbar extends ViewPart { ...@@ -34,6 +34,7 @@ export class EditorScrollbar extends ViewPart {
const scrollbar = options.get(EditorOption.scrollbar); const scrollbar = options.get(EditorOption.scrollbar);
const mouseWheelScrollSensitivity = options.get(EditorOption.mouseWheelScrollSensitivity); const mouseWheelScrollSensitivity = options.get(EditorOption.mouseWheelScrollSensitivity);
const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity); const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity);
const scrollPredominantAxis = options.get(EditorOption.scrollPredominantAxis);
const scrollbarOptions: ScrollableElementCreationOptions = { const scrollbarOptions: ScrollableElementCreationOptions = {
listenOnDomNode: viewDomNode.domNode, listenOnDomNode: viewDomNode.domNode,
...@@ -54,6 +55,7 @@ export class EditorScrollbar extends ViewPart { ...@@ -54,6 +55,7 @@ export class EditorScrollbar extends ViewPart {
arrowSize: scrollbar.arrowSize, arrowSize: scrollbar.arrowSize,
mouseWheelScrollSensitivity: mouseWheelScrollSensitivity, mouseWheelScrollSensitivity: mouseWheelScrollSensitivity,
fastScrollSensitivity: fastScrollSensitivity, fastScrollSensitivity: fastScrollSensitivity,
scrollPredominantAxis: scrollPredominantAxis,
}; };
this.scrollbar = this._register(new SmoothScrollableElement(linesContent.domNode, scrollbarOptions, this._context.viewLayout.getScrollable())); this.scrollbar = this._register(new SmoothScrollableElement(linesContent.domNode, scrollbarOptions, this._context.viewLayout.getScrollable()));
...@@ -140,10 +142,12 @@ export class EditorScrollbar extends ViewPart { ...@@ -140,10 +142,12 @@ export class EditorScrollbar extends ViewPart {
const scrollbar = options.get(EditorOption.scrollbar); const scrollbar = options.get(EditorOption.scrollbar);
const mouseWheelScrollSensitivity = options.get(EditorOption.mouseWheelScrollSensitivity); const mouseWheelScrollSensitivity = options.get(EditorOption.mouseWheelScrollSensitivity);
const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity); const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity);
const scrollPredominantAxis = options.get(EditorOption.scrollPredominantAxis);
const newOpts: ScrollableElementChangeOptions = { const newOpts: ScrollableElementChangeOptions = {
handleMouseWheel: scrollbar.handleMouseWheel, handleMouseWheel: scrollbar.handleMouseWheel,
mouseWheelScrollSensitivity: mouseWheelScrollSensitivity, mouseWheelScrollSensitivity: mouseWheelScrollSensitivity,
fastScrollSensitivity: fastScrollSensitivity fastScrollSensitivity: fastScrollSensitivity,
scrollPredominantAxis: scrollPredominantAxis
}; };
this.scrollbar.updateOptions(newOpts); this.scrollbar.updateOptions(newOpts);
} }
......
...@@ -319,6 +319,11 @@ export interface IEditorOptions { ...@@ -319,6 +319,11 @@ export interface IEditorOptions {
* Defaults to 5. * Defaults to 5.
*/ */
fastScrollSensitivity?: number; fastScrollSensitivity?: number;
/**
* Enable that the editor scrolls only the predominant axis. Prevents horizontal drift when scrolling vertically on a trackpad.
* Defaults to true.
*/
scrollPredominantAxis?: boolean;
/** /**
* The modifier to be used to add multiple cursors with the mouse. * The modifier to be used to add multiple cursors with the mouse.
* Defaults to 'alt' * Defaults to 'alt'
...@@ -3193,6 +3198,7 @@ export const enum EditorOption { ...@@ -3193,6 +3198,7 @@ export const enum EditorOption {
scrollbar, scrollbar,
scrollBeyondLastColumn, scrollBeyondLastColumn,
scrollBeyondLastLine, scrollBeyondLastLine,
scrollPredominantAxis,
selectionClipboard, selectionClipboard,
selectionHighlight, selectionHighlight,
selectOnLineNumbers, selectOnLineNumbers,
...@@ -3651,6 +3657,10 @@ export const EditorOptions = { ...@@ -3651,6 +3657,10 @@ export const EditorOptions = {
EditorOption.scrollBeyondLastLine, 'scrollBeyondLastLine', true, EditorOption.scrollBeyondLastLine, 'scrollBeyondLastLine', true,
{ description: nls.localize('scrollBeyondLastLine', "Controls whether the editor will scroll beyond the last line.") } { description: nls.localize('scrollBeyondLastLine', "Controls whether the editor will scroll beyond the last line.") }
)), )),
scrollPredominantAxis: register(new EditorBooleanOption(
EditorOption.scrollPredominantAxis, 'scrollPredominantAxis', true,
{ 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.") }
)),
selectionClipboard: register(new EditorBooleanOption( selectionClipboard: register(new EditorBooleanOption(
EditorOption.selectionClipboard, 'selectionClipboard', true, EditorOption.selectionClipboard, 'selectionClipboard', true,
{ {
......
...@@ -247,34 +247,35 @@ export enum EditorOption { ...@@ -247,34 +247,35 @@ export enum EditorOption {
scrollbar = 79, scrollbar = 79,
scrollBeyondLastColumn = 80, scrollBeyondLastColumn = 80,
scrollBeyondLastLine = 81, scrollBeyondLastLine = 81,
selectionClipboard = 82, scrollPredominantAxis = 82,
selectionHighlight = 83, selectionClipboard = 83,
selectOnLineNumbers = 84, selectionHighlight = 84,
showFoldingControls = 85, selectOnLineNumbers = 85,
showUnused = 86, showFoldingControls = 86,
snippetSuggestions = 87, showUnused = 87,
smoothScrolling = 88, snippetSuggestions = 88,
stopRenderingLineAfter = 89, smoothScrolling = 89,
suggest = 90, stopRenderingLineAfter = 90,
suggestFontSize = 91, suggest = 91,
suggestLineHeight = 92, suggestFontSize = 92,
suggestOnTriggerCharacters = 93, suggestLineHeight = 93,
suggestSelection = 94, suggestOnTriggerCharacters = 94,
tabCompletion = 95, suggestSelection = 95,
useTabStops = 96, tabCompletion = 96,
wordSeparators = 97, useTabStops = 97,
wordWrap = 98, wordSeparators = 98,
wordWrapBreakAfterCharacters = 99, wordWrap = 99,
wordWrapBreakBeforeCharacters = 100, wordWrapBreakAfterCharacters = 100,
wordWrapColumn = 101, wordWrapBreakBeforeCharacters = 101,
wordWrapMinified = 102, wordWrapColumn = 102,
wrappingIndent = 103, wordWrapMinified = 103,
wrappingStrategy = 104, wrappingIndent = 104,
editorClassName = 105, wrappingStrategy = 105,
pixelRatio = 106, editorClassName = 106,
tabFocusMode = 107, pixelRatio = 107,
layoutInfo = 108, tabFocusMode = 108,
wrappingInfo = 109 layoutInfo = 109,
wrappingInfo = 110
} }
/** /**
......
...@@ -2794,6 +2794,11 @@ declare namespace monaco.editor { ...@@ -2794,6 +2794,11 @@ declare namespace monaco.editor {
* Defaults to 5. * Defaults to 5.
*/ */
fastScrollSensitivity?: number; fastScrollSensitivity?: number;
/**
* Enable that the editor scrolls only the predominant axis. Prevents horizontal drift when scrolling vertically on a trackpad.
* Defaults to true.
*/
scrollPredominantAxis?: boolean;
/** /**
* The modifier to be used to add multiple cursors with the mouse. * The modifier to be used to add multiple cursors with the mouse.
* Defaults to 'alt' * Defaults to 'alt'
...@@ -3772,34 +3777,35 @@ declare namespace monaco.editor { ...@@ -3772,34 +3777,35 @@ declare namespace monaco.editor {
scrollbar = 79, scrollbar = 79,
scrollBeyondLastColumn = 80, scrollBeyondLastColumn = 80,
scrollBeyondLastLine = 81, scrollBeyondLastLine = 81,
selectionClipboard = 82, scrollPredominantAxis = 82,
selectionHighlight = 83, selectionClipboard = 83,
selectOnLineNumbers = 84, selectionHighlight = 84,
showFoldingControls = 85, selectOnLineNumbers = 85,
showUnused = 86, showFoldingControls = 86,
snippetSuggestions = 87, showUnused = 87,
smoothScrolling = 88, snippetSuggestions = 88,
stopRenderingLineAfter = 89, smoothScrolling = 89,
suggest = 90, stopRenderingLineAfter = 90,
suggestFontSize = 91, suggest = 91,
suggestLineHeight = 92, suggestFontSize = 92,
suggestOnTriggerCharacters = 93, suggestLineHeight = 93,
suggestSelection = 94, suggestOnTriggerCharacters = 94,
tabCompletion = 95, suggestSelection = 95,
useTabStops = 96, tabCompletion = 96,
wordSeparators = 97, useTabStops = 97,
wordWrap = 98, wordSeparators = 98,
wordWrapBreakAfterCharacters = 99, wordWrap = 99,
wordWrapBreakBeforeCharacters = 100, wordWrapBreakAfterCharacters = 100,
wordWrapColumn = 101, wordWrapBreakBeforeCharacters = 101,
wordWrapMinified = 102, wordWrapColumn = 102,
wrappingIndent = 103, wordWrapMinified = 103,
wrappingStrategy = 104, wrappingIndent = 104,
editorClassName = 105, wrappingStrategy = 105,
pixelRatio = 106, editorClassName = 106,
tabFocusMode = 107, pixelRatio = 107,
layoutInfo = 108, tabFocusMode = 108,
wrappingInfo = 109 layoutInfo = 109,
wrappingInfo = 110
} }
export const EditorOptions: { export const EditorOptions: {
acceptSuggestionOnCommitCharacter: IEditorOption<EditorOption.acceptSuggestionOnCommitCharacter, boolean>; acceptSuggestionOnCommitCharacter: IEditorOption<EditorOption.acceptSuggestionOnCommitCharacter, boolean>;
...@@ -3884,6 +3890,7 @@ declare namespace monaco.editor { ...@@ -3884,6 +3890,7 @@ declare namespace monaco.editor {
scrollbar: IEditorOption<EditorOption.scrollbar, InternalEditorScrollbarOptions>; scrollbar: IEditorOption<EditorOption.scrollbar, InternalEditorScrollbarOptions>;
scrollBeyondLastColumn: IEditorOption<EditorOption.scrollBeyondLastColumn, number>; scrollBeyondLastColumn: IEditorOption<EditorOption.scrollBeyondLastColumn, number>;
scrollBeyondLastLine: IEditorOption<EditorOption.scrollBeyondLastLine, boolean>; scrollBeyondLastLine: IEditorOption<EditorOption.scrollBeyondLastLine, boolean>;
scrollPredominantAxis: IEditorOption<EditorOption.scrollPredominantAxis, boolean>;
selectionClipboard: IEditorOption<EditorOption.selectionClipboard, boolean>; selectionClipboard: IEditorOption<EditorOption.selectionClipboard, boolean>;
selectionHighlight: IEditorOption<EditorOption.selectionHighlight, boolean>; selectionHighlight: IEditorOption<EditorOption.selectionHighlight, boolean>;
selectOnLineNumbers: IEditorOption<EditorOption.selectOnLineNumbers, boolean>; selectOnLineNumbers: IEditorOption<EditorOption.selectOnLineNumbers, boolean>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册