Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Rename option to scrollByPage
  • Loading branch information
alexdima committed Nov 9, 2020
commit abcc6218725bc14c68c9780691ded463e48af4c4
20 changes: 9 additions & 11 deletions src/vs/base/browser/ui/scrollbar/abstractScrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export interface AbstractScrollbarOptions {
visibility: ScrollbarVisibility;
extraScrollbarClassName: string;
scrollable: Scrollable;
gutterClickMovesByPage: boolean;
scrollByPage: boolean;
}

export abstract class AbstractScrollbar extends Widget {

protected _host: ScrollbarHost;
protected _scrollable: Scrollable;
protected _gutterClickMovesByPage: boolean;
protected _scrollByPage: boolean;
private _lazyRender: boolean;
protected _scrollbarState: ScrollbarState;
private _visibilityController: ScrollbarVisibilityController;
Expand All @@ -61,7 +61,7 @@ export abstract class AbstractScrollbar extends Widget {
this._lazyRender = opts.lazyRender;
this._host = opts.host;
this._scrollable = opts.scrollable;
this._gutterClickMovesByPage = opts.gutterClickMovesByPage;
this._scrollByPage = opts.scrollByPage;
this._scrollbarState = opts.scrollbarState;
this._visibilityController = this._register(new ScrollbarVisibilityController(opts.visibility, 'visible scrollbar ' + opts.extraScrollbarClassName, 'invisible scrollbar ' + opts.extraScrollbarClassName));
this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded());
Expand Down Expand Up @@ -214,14 +214,12 @@ export abstract class AbstractScrollbar extends Widget {
offsetY = e.posy - domNodePosition.top;
}

let offset = this._mouseDownRelativePosition(offsetX, offsetY);
let scrollPos: number;
if (this._gutterClickMovesByPage) {
scrollPos = this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(offset);
} else {
scrollPos = this._scrollbarState.getDesiredScrollPositionFromOffsetAbsolute(offset);
}
this._setDesiredScrollPositionNow(scrollPos);
const offset = this._mouseDownRelativePosition(offsetX, offsetY);
this._setDesiredScrollPositionNow(
this._scrollByPage
? this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(offset)
: this._scrollbarState.getDesiredScrollPositionFromOffset(offset)
);

if (e.leftButton) {
e.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/browser/ui/scrollbar/horizontalScrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class HorizontalScrollbar extends AbstractScrollbar {
visibility: options.horizontal,
extraScrollbarClassName: 'horizontal',
scrollable: scrollable,
gutterClickMovesByPage: options.gutterClickMovesByPage
scrollByPage: options.scrollByPage
});

if (options.horizontalHasArrows) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/browser/ui/scrollbar/scrollableElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ function resolveOptions(opts: ScrollableElementCreationOptions): ScrollableEleme
verticalHasArrows: (typeof opts.verticalHasArrows !== 'undefined' ? opts.verticalHasArrows : false),
verticalSliderSize: (typeof opts.verticalSliderSize !== 'undefined' ? opts.verticalSliderSize : 0),

gutterClickMovesByPage: (typeof opts.gutterClickMovesByPage !== 'undefined' ? opts.gutterClickMovesByPage : false)
scrollByPage: (typeof opts.scrollByPage !== 'undefined' ? opts.scrollByPage : false)
};

result.horizontalSliderSize = (typeof opts.horizontalSliderSize !== 'undefined' ? opts.horizontalSliderSize : result.horizontalScrollbarSize);
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/browser/ui/scrollbar/scrollableElementOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export interface ScrollableElementCreationOptions {
* Scroll gutter clicks move by page vs. jump to position.
* Defaults to false.
*/
gutterClickMovesByPage?: boolean;
scrollByPage?: boolean;
}

export interface ScrollableElementChangeOptions {
Expand Down Expand Up @@ -151,5 +151,5 @@ export interface ScrollableElementResolvedOptions {
verticalScrollbarSize: number;
verticalSliderSize: number;
verticalHasArrows: boolean;
gutterClickMovesByPage: boolean;
scrollByPage: boolean;
}
2 changes: 1 addition & 1 deletion src/vs/base/browser/ui/scrollbar/scrollbarState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class ScrollbarState {
* Compute a desired `scrollPosition` such that `offset` ends up in the center of the slider.
* `offset` is based on the same coordinate system as the `sliderPosition`.
*/
public getDesiredScrollPositionFromOffsetAbsolute(offset: number): number {
public getDesiredScrollPositionFromOffset(offset: number): number {
if (!this._computedIsNeeded) {
// no need for a slider
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/browser/ui/scrollbar/verticalScrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class VerticalScrollbar extends AbstractScrollbar {
visibility: options.vertical,
extraScrollbarClassName: 'vertical',
scrollable: scrollable,
gutterClickMovesByPage: options.gutterClickMovesByPage
scrollByPage: options.scrollByPage
});

if (options.verticalHasArrows) {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/test/browser/ui/scrollbar/scrollbarState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ suite('ScrollbarState', () => {
assert.equal(actual.getSliderSize(), 20);
assert.equal(actual.getSliderPosition(), 249);

assert.equal(actual.getDesiredScrollPositionFromOffsetAbsolute(259), 32849);
assert.equal(actual.getDesiredScrollPositionFromOffset(259), 32849);

// 259 is greater than 230 so page down, 32787 + 339 = 33126
assert.equal(actual.getDesiredScrollPositionFromOffsetPaged(259), 33126);
Expand All @@ -44,7 +44,7 @@ suite('ScrollbarState', () => {
assert.equal(actual.getSliderSize(), 20);
assert.equal(actual.getSliderPosition(), 230);

assert.equal(actual.getDesiredScrollPositionFromOffsetAbsolute(240 + 12), 32811);
assert.equal(actual.getDesiredScrollPositionFromOffset(240 + 12), 32811);

// 240 + 12 = 252; greater than 230 so page down, 32787 + 339 = 33126
assert.equal(actual.getDesiredScrollPositionFromOffsetPaged(240 + 12), 33126);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class EditorScrollbar extends ViewPart {
mouseWheelScrollSensitivity: mouseWheelScrollSensitivity,
fastScrollSensitivity: fastScrollSensitivity,
scrollPredominantAxis: scrollPredominantAxis,
gutterClickMovesByPage: scrollbar.gutterClickMovesByPage,
scrollByPage: scrollbar.scrollByPage,
};

this.scrollbar = this._register(new SmoothScrollableElement(linesContent.domNode, scrollbarOptions, this._context.viewLayout.getScrollable()));
Expand Down
8 changes: 4 additions & 4 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2924,7 +2924,7 @@ export interface IEditorScrollbarOptions {
* Scroll gutter clicks move by page vs jump to position.
* Defaults to false.
*/
gutterClickMovesByPage?: boolean;
scrollByPage?: boolean;
}

export interface InternalEditorScrollbarOptions {
Expand All @@ -2940,7 +2940,7 @@ export interface InternalEditorScrollbarOptions {
readonly horizontalSliderSize: number;
readonly verticalScrollbarSize: number;
readonly verticalSliderSize: number;
readonly gutterClickMovesByPage: boolean;
readonly scrollByPage: boolean;
}

function _scrollbarVisibilityFromString(visibility: string | undefined, defaultValue: ScrollbarVisibility): ScrollbarVisibility {
Expand Down Expand Up @@ -2972,7 +2972,7 @@ class EditorScrollbar extends BaseEditorOption<EditorOption.scrollbar, InternalE
verticalSliderSize: 14,
handleMouseWheel: true,
alwaysConsumeMouseWheel: true,
gutterClickMovesByPage: false
scrollByPage: false
}
);
}
Expand All @@ -2997,7 +2997,7 @@ class EditorScrollbar extends BaseEditorOption<EditorOption.scrollbar, InternalE
horizontalSliderSize: EditorIntOption.clampedInt(input.horizontalSliderSize, horizontalScrollbarSize, 0, 1000),
verticalScrollbarSize: verticalScrollbarSize,
verticalSliderSize: EditorIntOption.clampedInt(input.verticalSliderSize, verticalScrollbarSize, 0, 1000),
gutterClickMovesByPage: EditorBooleanOption.boolean(input.gutterClickMovesByPage, this.defaultValue.gutterClickMovesByPage),
scrollByPage: EditorBooleanOption.boolean(input.scrollByPage, this.defaultValue.scrollByPage),
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ suite('Editor ViewLayout - EditorLayoutProvider', () => {
horizontalSliderSize: EditorOptions.scrollbar.defaultValue.horizontalSliderSize,
verticalScrollbarSize: input.verticalScrollbarWidth,
verticalSliderSize: EditorOptions.scrollbar.defaultValue.verticalSliderSize,
gutterClickMovesByPage: EditorOptions.scrollbar.defaultValue.gutterClickMovesByPage,
scrollByPage: EditorOptions.scrollbar.defaultValue.scrollByPage,
};
options._write(EditorOption.scrollbar, scrollbarOptions);
const lineNumbersOptions: InternalEditorRenderLineNumbersOptions = {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3664,7 +3664,7 @@ declare namespace monaco.editor {
* Scroll gutter clicks move by page vs jump to position.
* Defaults to false.
*/
gutterClickMovesByPage?: boolean;
scrollByPage?: boolean;
}

export interface InternalEditorScrollbarOptions {
Expand All @@ -3680,7 +3680,7 @@ declare namespace monaco.editor {
readonly horizontalSliderSize: number;
readonly verticalScrollbarSize: number;
readonly verticalSliderSize: number;
readonly gutterClickMovesByPage: boolean;
readonly scrollByPage: boolean;
}

/**
Expand Down