Skip to content
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

Implement smooth scrolling feature #25286

Merged
merged 16 commits into from
Aug 22, 2017
Merged
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
14 changes: 7 additions & 7 deletions src/vs/base/browser/ui/list/listView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class ListView<T> implements IDisposable {

const scrollHeight = this.getContentHeight();
this.rowsContainer.style.height = `${scrollHeight}px`;
this.scrollableElement.updateState({ scrollHeight });
this.scrollableElement.setScrollDimensions({ scrollHeight });

return deleted.map(i => i.element);
}
Expand All @@ -134,8 +134,8 @@ export class ListView<T> implements IDisposable {
}

get renderHeight(): number {
const scrollState = this.scrollableElement.getScrollState();
return scrollState.height;
const scrollDimensions = this.scrollableElement.getScrollDimensions();
return scrollDimensions.height;
}

element(index: number): T {
Expand Down Expand Up @@ -164,7 +164,7 @@ export class ListView<T> implements IDisposable {
}

layout(height?: number): void {
this.scrollableElement.updateState({
this.scrollableElement.setScrollDimensions({
height: height || DOM.getContentHeight(this._domNode)
});
}
Expand Down Expand Up @@ -221,12 +221,12 @@ export class ListView<T> implements IDisposable {
}

getScrollTop(): number {
const scrollState = this.scrollableElement.getScrollState();
return scrollState.scrollTop;
const scrollPosition = this.scrollableElement.getScrollPosition();
return scrollPosition.scrollTop;
}

setScrollTop(scrollTop: number): void {
this.scrollableElement.updateState({ scrollTop });
this.scrollableElement.setScrollPosition({ scrollTop });
}

get scrollTop(): number {
Expand Down
26 changes: 9 additions & 17 deletions src/vs/base/browser/ui/scrollbar/abstractScrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode';
import { ScrollbarState } from 'vs/base/browser/ui/scrollbar/scrollbarState';
import { ScrollbarArrow, ScrollbarArrowOptions } from 'vs/base/browser/ui/scrollbar/scrollbarArrow';
import { ScrollbarVisibilityController } from 'vs/base/browser/ui/scrollbar/scrollbarVisibilityController';
import { Scrollable, ScrollbarVisibility } from 'vs/base/common/scrollable';
import { Scrollable, ScrollbarVisibility, INewScrollPosition } from 'vs/base/common/scrollable';

/**
* The orthogonal distance to the slider at which dragging "resets". This implements "snapping"
Expand Down Expand Up @@ -193,7 +193,7 @@ export abstract class AbstractScrollbar extends Widget {

private _onMouseDown(e: IMouseEvent): void {
let domNodePosition = DomUtils.getDomNodePagePosition(this.domNode.domNode);
this.setDesiredScrollPosition(this._scrollbarState.getDesiredScrollPositionFromOffset(this._mouseDownRelativePosition(e, domNodePosition)));
this._setDesiredScrollPositionNow(this._scrollbarState.getDesiredScrollPositionFromOffset(this._mouseDownRelativePosition(e, domNodePosition)));
if (e.leftButton) {
e.preventDefault();
this._sliderMouseDown(e, () => { /*nothing to do*/ });
Expand All @@ -214,13 +214,13 @@ export abstract class AbstractScrollbar extends Widget {

if (Platform.isWindows && mouseOrthogonalDelta > MOUSE_DRAG_RESET_DISTANCE) {
// The mouse has wondered away from the scrollbar => reset dragging
this.setDesiredScrollPosition(initialScrollbarState.getScrollPosition());
this._setDesiredScrollPositionNow(initialScrollbarState.getScrollPosition());
return;
}

const mousePosition = this._sliderMousePosition(mouseMoveData);
const mouseDelta = mousePosition - initialMousePosition;
this.setDesiredScrollPosition(initialScrollbarState.getDesiredScrollPositionFromDelta(mouseDelta));
this._setDesiredScrollPositionNow(initialScrollbarState.getDesiredScrollPositionFromDelta(mouseDelta));
},
() => {
this.slider.toggleClassName('active', false);
Expand All @@ -232,18 +232,12 @@ export abstract class AbstractScrollbar extends Widget {
this._host.onDragStart();
}

public setDesiredScrollPosition(desiredScrollPosition: number): boolean {
desiredScrollPosition = this.validateScrollPosition(desiredScrollPosition);
private _setDesiredScrollPositionNow(_desiredScrollPosition: number): void {

let oldScrollPosition = this._getScrollPosition();
this._setScrollPosition(desiredScrollPosition);
let newScrollPosition = this._getScrollPosition();
let desiredScrollPosition: INewScrollPosition = {};
this.writeScrollPosition(desiredScrollPosition, _desiredScrollPosition);

if (oldScrollPosition !== newScrollPosition) {
this._onElementScrollPosition(this._getScrollPosition());
return true;
}
return false;
this._scrollable.setScrollPositionNow(desiredScrollPosition);
}

// ----------------- Overwrite these
Expand All @@ -255,7 +249,5 @@ export abstract class AbstractScrollbar extends Widget {
protected abstract _sliderMousePosition(e: ISimplifiedMouseEvent): number;
protected abstract _sliderOrthogonalMousePosition(e: ISimplifiedMouseEvent): number;

protected abstract _getScrollPosition(): number;
protected abstract _setScrollPosition(elementScrollPosition: number): void;
public abstract validateScrollPosition(desiredScrollPosition: number): number;
public abstract writeScrollPosition(target: INewScrollPosition, scrollPosition: number): void;
}
17 changes: 3 additions & 14 deletions src/vs/base/browser/ui/scrollbar/horizontalScrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AbstractScrollbar, ScrollbarHost, ISimplifiedMouseEvent } from 'vs/base
import { StandardMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { IDomNodePagePosition } from 'vs/base/browser/dom';
import { ScrollableElementResolvedOptions } from 'vs/base/browser/ui/scrollbar/scrollableElementOptions';
import { Scrollable, ScrollEvent, ScrollbarVisibility } from 'vs/base/common/scrollable';
import { Scrollable, ScrollEvent, ScrollbarVisibility, INewScrollPosition } from 'vs/base/common/scrollable';
import { ScrollbarState } from 'vs/base/browser/ui/scrollbar/scrollbarState';
import { ARROW_IMG_SIZE } from 'vs/base/browser/ui/scrollbar/scrollbarArrow';

Expand Down Expand Up @@ -89,18 +89,7 @@ export class HorizontalScrollbar extends AbstractScrollbar {
return e.posy;
}

protected _getScrollPosition(): number {
const scrollState = this._scrollable.getState();
return scrollState.scrollLeft;
}

protected _setScrollPosition(scrollPosition: number) {
this._scrollable.updateState({
scrollLeft: scrollPosition
});
}

public validateScrollPosition(desiredScrollPosition: number): number {
return this._scrollable.validateScrollLeft(desiredScrollPosition);
public writeScrollPosition(target: INewScrollPosition, scrollPosition: number): void {
target.scrollLeft = scrollPosition;
}
}
Loading