diff --git a/src/vs/editor/browser/viewParts/lines/viewLines.ts b/src/vs/editor/browser/viewParts/lines/viewLines.ts index 2b9d5020db445e76c3e3deafb8bc66d0147186c8..cac0f2175ff59c751ddef42b5bd38af9af5ca6ee 100644 --- a/src/vs/editor/browser/viewParts/lines/viewLines.ts +++ b/src/vs/editor/browser/viewParts/lines/viewLines.ts @@ -115,24 +115,9 @@ export class ViewLines extends ViewLayer { return true; } - public onCursorLineScroll(e:EditorCommon.IViewLineScrollEvent): boolean { - var currentViewport = this._layoutProvider.getCurrentViewport(); - var residualOffset = currentViewport.top - this._layoutProvider.getVerticalOffsetForLineNumber(this._currentVisibleRange.startLineNumber); - var newTopLineNumber: number; - if (e.lineOffset < 0) { - newTopLineNumber = this._currentVisibleRange.startLineNumber + e.lineOffset; - if (newTopLineNumber < 1) { - newTopLineNumber = 1; - residualOffset = 0; - } - } else { - newTopLineNumber = this._currentVisibleRange.startLineNumber + e.lineOffset; - if (newTopLineNumber > this._currentVisibleRange.endLineNumber) { - newTopLineNumber = this._currentVisibleRange.endLineNumber; - residualOffset = 0; - } - } - var newScrollTop = this._layoutProvider.getVerticalOffsetForLineNumber(newTopLineNumber) + residualOffset; + public onCursorScrollRequest(e:EditorCommon.IViewScrollRequestEvent): boolean { + let currentScrollTop = this._layoutProvider.getScrollTop(); + let newScrollTop = currentScrollTop + e.deltaLines * this._context.configuration.editor.lineHeight; this._layoutProvider.setScrollTop(newScrollTop); return true; } diff --git a/src/vs/editor/common/config/commonEditorConfig.ts b/src/vs/editor/common/config/commonEditorConfig.ts index a720151d03425b32ee30291921e651533b4e388d..f4f3d0ec1bfbc3379e5d6fbc3cdb0289c6b0793c 100644 --- a/src/vs/editor/common/config/commonEditorConfig.ts +++ b/src/vs/editor/common/config/commonEditorConfig.ts @@ -166,7 +166,7 @@ class InternalEditorOptionsHelper { outlineMarkers: toBoolean(opts.outlineMarkers), referenceInfos: toBoolean(opts.referenceInfos), renderWhitespace: toBoolean(opts.renderWhitespace), - scrollCursorWithLine: toBoolean(opts.scrollCursorWithLine), + moveCursorWhenScrolling: toBoolean(opts.moveCursorWhenScrolling), layoutInfo: layoutInfo, stylingInfo: { @@ -818,10 +818,10 @@ configurationRegistry.registerConfiguration({ 'default': DefaultConfig.editor.referenceInfos, 'description': nls.localize('referenceInfos', "Controls if the editor shows reference information for the modes that support it") }, - 'editor.scrollCursorWithLine' : { + 'editor.moveCursorWhenScrolling' : { 'type': 'boolean', - 'default': DefaultConfig.editor.scrollCursorWithLine, - 'description': nls.localize('scrollCursorWithLine', "Controls if the edition cursor moves when the user scrolls the editor line by line") + 'default': DefaultConfig.editor.moveCursorWhenScrolling, + 'description': nls.localize('moveCursorWhenScrolling', "Controls if the edition cursor moves when the user scrolls the editor line by line") }, 'diffEditor.renderSideBySide' : { 'type': 'boolean', diff --git a/src/vs/editor/common/config/config.ts b/src/vs/editor/common/config/config.ts index 1873744ba60a62b8293c7e4a484b70cf2a3f1918..3e2dc136b7c70c9d372d3d9fc70fa6e2d24398ef 100644 --- a/src/vs/editor/common/config/config.ts +++ b/src/vs/editor/common/config/config.ts @@ -208,6 +208,13 @@ registerCoreCommand(H.ScrollLineDown, { primary: KeyMod.CtrlCmd | KeyCode.DownArrow }); +registerCoreCommand(H.ScrollPageUp, { + primary: KeyMod.CtrlCmd | KeyCode.PageUp +}); +registerCoreCommand(H.ScrollPageDown, { + primary: KeyMod.CtrlCmd | KeyCode.PageDown +}); + registerCoreCommand(H.Tab, { primary: KeyCode.Tab }, KeybindingsRegistry.WEIGHT.editorCore(), [ diff --git a/src/vs/editor/common/config/defaultConfig.ts b/src/vs/editor/common/config/defaultConfig.ts index c9b0f3a9d863f4bf9ee7713277339f86bb1f8a04..282c8f046e9515c9b0d5fa701483da739ee8b6b5 100644 --- a/src/vs/editor/common/config/defaultConfig.ts +++ b/src/vs/editor/common/config/defaultConfig.ts @@ -62,7 +62,7 @@ class ConfigClass implements IConfiguration { outlineMarkers: false, referenceInfos: true, renderWhitespace: false, - scrollCursorWithLine: false, + moveCursorWhenScrolling: false, tabSize: 4, insertSpaces: true, diff --git a/src/vs/editor/common/controller/cursor.ts b/src/vs/editor/common/controller/cursor.ts index cb39610efa6d131404bcac559c44a40dcb3e3c0c..28d57e0d6f2b1dacb57b3ff63adb2f0733fb242c 100644 --- a/src/vs/editor/common/controller/cursor.ts +++ b/src/vs/editor/common/controller/cursor.ts @@ -41,7 +41,7 @@ interface IMultipleCursorOperationContext { isCursorUndo: boolean; executeCommands: EditorCommon.ICommand[]; postOperationRunnables: IPostOperationRunnable[]; - lineScrollOffset: number; + requestScrollDeltaLines: number; } interface IExecContext { @@ -87,7 +87,7 @@ export class Cursor extends EventEmitter { EditorCommon.EventType.CursorPositionChanged, EditorCommon.EventType.CursorSelectionChanged, EditorCommon.EventType.CursorRevealRange, - EditorCommon.EventType.CursorLineScroll + EditorCommon.EventType.CursorScrollRequest ]); this.editorId = editorId; this.configuration = configuration; @@ -309,7 +309,7 @@ export class Cursor extends EventEmitter { postOperationRunnables: [], shouldPushStackElementBefore: false, shouldPushStackElementAfter: false, - lineScrollOffset: 0 + requestScrollDeltaLines: 0 }; callback(currentHandlerCtx); @@ -339,7 +339,7 @@ export class Cursor extends EventEmitter { var shouldRevealHorizontal: boolean; var shouldRevealTarget: RevealTarget; var isCursorUndo: boolean; - var lineScrollOffset: number; + var requestScrollDeltaLines: number; var hasExecutedCommands = this._createAndInterpretHandlerCtx(eventSource, e.getData(), (currentHandlerCtx:IMultipleCursorOperationContext) => { handled = handler(currentHandlerCtx); @@ -350,7 +350,7 @@ export class Cursor extends EventEmitter { shouldRevealVerticalInCenter = currentHandlerCtx.shouldRevealVerticalInCenter; shouldRevealHorizontal = currentHandlerCtx.shouldRevealHorizontal; isCursorUndo = currentHandlerCtx.isCursorUndo; - lineScrollOffset = currentHandlerCtx.lineScrollOffset; + requestScrollDeltaLines = currentHandlerCtx.requestScrollDeltaLines; }); if (hasExecutedCommands) { @@ -408,8 +408,8 @@ export class Cursor extends EventEmitter { this.emitCursorSelectionChanged(eventSource, cursorPositionChangeReason); } - if (lineScrollOffset) { - this.emitCursorLineScroll(lineScrollOffset); + if (requestScrollDeltaLines) { + this.emitCursorScrollRequest(requestScrollDeltaLines); } } catch (err) { Errors.onUnexpectedError(err); @@ -854,11 +854,11 @@ export class Cursor extends EventEmitter { this.emit(EditorCommon.EventType.CursorSelectionChanged, e); } - private emitCursorLineScroll(lineScrollOffset: number): void { - var e:EditorCommon.ICursorLineScrollEvent = { - lineOffset: lineScrollOffset + private emitCursorScrollRequest(lineScrollOffset: number): void { + var e:EditorCommon.ICursorScrollRequestEvent = { + deltaLines: lineScrollOffset }; - this.emit(EditorCommon.EventType.CursorLineScroll, e); + this.emit(EditorCommon.EventType.CursorScrollRequest, e); } private emitCursorRevealRange(revealTarget: RevealTarget, verticalType: EditorCommon.VerticalRevealType, revealHorizontal: boolean): void { @@ -974,8 +974,10 @@ export class Cursor extends EventEmitter { handlersMap[H.Outdent] = (ctx:IMultipleCursorOperationContext) => this._outdent(ctx); handlersMap[H.Paste] = (ctx:IMultipleCursorOperationContext) => this._paste(ctx); - handlersMap[H.ScrollLineUp] = (ctx:IMultipleCursorOperationContext) => this._scrollLineUp(ctx); - handlersMap[H.ScrollLineDown] = (ctx:IMultipleCursorOperationContext) => this._scrollLineDown(ctx); + handlersMap[H.ScrollLineUp] = (ctx:IMultipleCursorOperationContext) => this._scrollUp(false, ctx); + handlersMap[H.ScrollLineDown] = (ctx:IMultipleCursorOperationContext) => this._scrollDown(false, ctx); + handlersMap[H.ScrollPageUp] = (ctx:IMultipleCursorOperationContext) => this._scrollUp(true, ctx); + handlersMap[H.ScrollPageDown] = (ctx:IMultipleCursorOperationContext) => this._scrollDown(true, ctx); handlersMap[H.DeleteLeft] = (ctx:IMultipleCursorOperationContext) => this._deleteLeft(ctx); handlersMap[H.DeleteWordLeft] = (ctx:IMultipleCursorOperationContext) => this._deleteWordLeft(ctx); @@ -1024,7 +1026,7 @@ export class Cursor extends EventEmitter { postOperationRunnable: null, shouldPushStackElementBefore: false, shouldPushStackElementAfter: false, - lineScrollOffset: 0 + requestScrollDeltaLines: 0 }; result = callable(i, cursors[i], context) || result; @@ -1034,7 +1036,7 @@ export class Cursor extends EventEmitter { ctx.shouldRevealHorizontal = context.shouldRevealHorizontal; ctx.shouldReveal = context.shouldReveal; ctx.shouldRevealVerticalInCenter = context.shouldRevealVerticalInCenter; - ctx.lineScrollOffset = context.lineScrollOffset; + ctx.requestScrollDeltaLines = context.requestScrollDeltaLines; } ctx.shouldPushStackElementBefore = ctx.shouldPushStackElementBefore || context.shouldPushStackElementBefore; @@ -1319,18 +1321,20 @@ export class Cursor extends EventEmitter { } } - private _scrollLineUp(ctx: IMultipleCursorOperationContext): boolean { - if (this.configuration.editor.scrollCursorWithLine) { - if (!this._moveUp(false, false, ctx)) return false; + private _scrollUp(isPaged: boolean, ctx: IMultipleCursorOperationContext): boolean { + if (this.configuration.editor.moveCursorWhenScrolling) { + if (!this._moveUp(false, isPaged, ctx)) { + return false; + } } - return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.scrollLineUp(oneCursor, oneCtx)); + ctx.requestScrollDeltaLines = isPaged ? -this.configuration.editor.pageSize : -1; } - private _scrollLineDown(ctx: IMultipleCursorOperationContext): boolean { - if (this.configuration.editor.scrollCursorWithLine) { - if (!this._moveDown(false, false, ctx)) return false; + private _scrollDown(isPaged: boolean, ctx: IMultipleCursorOperationContext): boolean { + if (this.configuration.editor.moveCursorWhenScrolling) { + if (!this._moveDown(false, isPaged, ctx)) return false; } - return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.scrollLineDown(oneCursor, oneCtx)); + ctx.requestScrollDeltaLines = isPaged ? this.configuration.editor.pageSize : 1; } private _distributePasteToCursors(ctx: IMultipleCursorOperationContext): string[] { diff --git a/src/vs/editor/common/controller/oneCursor.ts b/src/vs/editor/common/controller/oneCursor.ts index 49b440772d2a34fc611156aa2814e24e984cd01f..0867f6d09554f548d639a90158c12ea821ab9c8c 100644 --- a/src/vs/editor/common/controller/oneCursor.ts +++ b/src/vs/editor/common/controller/oneCursor.ts @@ -30,7 +30,7 @@ export interface IOneCursorOperationContext { shouldPushStackElementAfter: boolean; executeCommand: EditorCommon.ICommand; postOperationRunnable: IPostOperationRunnable; - lineScrollOffset: number; + requestScrollDeltaLines: number; } export interface IModeConfiguration { @@ -1335,16 +1335,6 @@ export class OneCursorOp { return true; } - public static scrollLineUp(cursor:OneCursor, ctx: IOneCursorOperationContext): boolean { - ctx.lineScrollOffset = -1; - return true; - } - - public static scrollLineDown(cursor:OneCursor, ctx: IOneCursorOperationContext): boolean { - ctx.lineScrollOffset = +1; - return true; - } - public static paste(cursor:OneCursor, text: string, pasteOnNewLine: boolean, ctx: IOneCursorOperationContext): boolean { let position = cursor.getPosition(); diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 510d2f66efd5c58f0bc64265b3b2af02c30e122a..6a2a6aa43686432aa82da03b692e1cff0f9b3266 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -486,7 +486,7 @@ export interface ICommonEditorOptions { * Make the cursor move with scrolling. * Defaults to false. */ - scrollCursorWithLine?: boolean; + moveCursorWhenScrolling?: boolean; } /** @@ -615,7 +615,7 @@ export interface IInternalEditorOptions { outlineMarkers: boolean; referenceInfos: boolean; renderWhitespace: boolean; - scrollCursorWithLine: boolean; + moveCursorWhenScrolling: boolean; // ---- Options that are computed @@ -2067,8 +2067,8 @@ export interface ICursorRevealRangeEvent { revealHorizontal:boolean; } -export interface ICursorLineScrollEvent { - lineOffset: number; +export interface ICursorScrollRequestEvent { + deltaLines: number; } export interface IModelChangedEvent { @@ -2513,7 +2513,7 @@ export var ViewEventNames = { CursorSelectionChangedEvent: 'cursorSelectionChangedEvent', RevealRangeEvent: 'revealRangeEvent', LineMappingChangedEvent: 'lineMappingChangedEvent', - LineScrollEvent: 'lineScrollEvent' + ScrollRequestEvent: 'scrollRequestEvent' }; export interface IScrollEvent { @@ -2610,8 +2610,8 @@ export interface IViewRevealRangeEvent { revealHorizontal: boolean; } -export interface IViewLineScrollEvent { - lineOffset: number; +export interface IViewScrollRequestEvent { + deltaLines: number; } export interface IViewWhitespaceViewportData { @@ -3246,7 +3246,7 @@ export var EventType = { CursorPositionChanged: 'positionChanged', CursorSelectionChanged: 'selectionChanged', CursorRevealRange: 'revealRange', - CursorLineScroll: 'lineScroll', + CursorScrollRequest: 'scrollRequest', ViewFocusGained: 'focusGained', ViewFocusLost: 'focusLost', @@ -3357,5 +3357,8 @@ export var Handler = { SelectAll: 'selectAll', ScrollLineUp: 'scrollLineUp', - ScrollLineDown: 'scrollLineDown' + ScrollLineDown: 'scrollLineDown', + + ScrollPageUp: 'scrollPageUp', + ScrollPageDown: 'scrollPageDown' }; diff --git a/src/vs/editor/common/viewModel/viewEventHandler.ts b/src/vs/editor/common/viewModel/viewEventHandler.ts index 6b059729b554a53fb293577f907bd53082aee39e..065c43d37c7b825ab0453c1dcc009c0eab1a6c52 100644 --- a/src/vs/editor/common/viewModel/viewEventHandler.ts +++ b/src/vs/editor/common/viewModel/viewEventHandler.ts @@ -47,7 +47,7 @@ export class ViewEventHandler { public onCursorRevealRange(e:EditorCommon.IViewRevealRangeEvent): boolean { return false; } - public onCursorLineScroll(e:EditorCommon.IViewLineScrollEvent): boolean { + public onCursorScrollRequest(e:EditorCommon.IViewScrollRequestEvent): boolean { return false; } public onConfigurationChanged(e:EditorCommon.IConfigurationChangedEvent): boolean { @@ -126,8 +126,8 @@ export class ViewEventHandler { this.shouldRender = this.onCursorRevealRange(data) || this.shouldRender; break; - case EditorCommon.ViewEventNames.LineScrollEvent: - this.shouldRender = this.onCursorLineScroll(data) || this.shouldRender; + case EditorCommon.ViewEventNames.ScrollRequestEvent: + this.shouldRender = this.onCursorScrollRequest(data) || this.shouldRender; break; case EditorCommon.EventType.ConfigurationChanged: diff --git a/src/vs/editor/common/viewModel/viewModel.ts b/src/vs/editor/common/viewModel/viewModel.ts index 31a451cf9b5db026a55dddc2dc15122468d9ef7b..2851eae9e3591e47875b0161a342a8d6015d90e2 100644 --- a/src/vs/editor/common/viewModel/viewModel.ts +++ b/src/vs/editor/common/viewModel/viewModel.ts @@ -235,8 +235,8 @@ export class ViewModel extends EventEmitter implements EditorCommon.IViewModel { this.onCursorRevealRange(data); break; - case EditorCommon.EventType.CursorLineScroll: - this.onCursorLineScroll(data); + case EditorCommon.EventType.CursorScrollRequest: + this.onCursorScrollRequest(data); break; case EditorCommon.EventType.ConfigurationChanged: @@ -343,8 +343,8 @@ export class ViewModel extends EventEmitter implements EditorCommon.IViewModel { private onCursorRevealRange(e:EditorCommon.ICursorRevealRangeEvent): void { this.cursors.onCursorRevealRange(e, (eventType:string, payload:any) => this.emit(eventType, payload)); } - private onCursorLineScroll(e:EditorCommon.ICursorLineScrollEvent): void { - this.cursors.onCursorLineScroll(e, (eventType:string, payload:any) => this.emit(eventType, payload)); + private onCursorScrollRequest(e:EditorCommon.ICursorScrollRequestEvent): void { + this.cursors.onCursorScrollRequest(e, (eventType:string, payload:any) => this.emit(eventType, payload)); } // --- end inbound event conversion diff --git a/src/vs/editor/common/viewModel/viewModelCursors.ts b/src/vs/editor/common/viewModel/viewModelCursors.ts index 8c7a12f8803d553c09318ba41aafd9767a6efc17..2c74e941d1ad6642edfdd93ae639289d9f3e2f97 100644 --- a/src/vs/editor/common/viewModel/viewModelCursors.ts +++ b/src/vs/editor/common/viewModel/viewModelCursors.ts @@ -105,11 +105,11 @@ export class ViewModelCursors { emit(EditorCommon.ViewEventNames.RevealRangeEvent, newEvent); } - public onCursorLineScroll(e:EditorCommon.ICursorLineScrollEvent, emit:(eventType:string, payload:any)=>void): void { - var newEvent:EditorCommon.IViewLineScrollEvent = { - lineOffset: e.lineOffset + public onCursorScrollRequest(e:EditorCommon.ICursorScrollRequestEvent, emit:(eventType:string, payload:any)=>void): void { + var newEvent:EditorCommon.IViewScrollRequestEvent = { + deltaLines: e.deltaLines }; - emit(EditorCommon.ViewEventNames.LineScrollEvent, newEvent); + emit(EditorCommon.ViewEventNames.ScrollRequestEvent, newEvent); } public onLineMappingChanged(emit:(eventType:string, payload:any)=>void): void {