提交 f992a924 编写于 作者: A Alex Dima

Tweaks for PR #1051: simplify view logic, renames, also add scroll page up/down

上级 0006d5d8
......@@ -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;
}
......
......@@ -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',
......
......@@ -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(), [
......
......@@ -62,7 +62,7 @@ class ConfigClass implements IConfiguration {
outlineMarkers: false,
referenceInfos: true,
renderWhitespace: false,
scrollCursorWithLine: false,
moveCursorWhenScrolling: false,
tabSize: 4,
insertSpaces: true,
......
......@@ -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[] {
......
......@@ -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();
......
......@@ -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'
};
......@@ -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(<EditorCommon.IViewRevealRangeEvent>data) || this.shouldRender;
break;
case EditorCommon.ViewEventNames.LineScrollEvent:
this.shouldRender = this.onCursorLineScroll(<EditorCommon.IViewLineScrollEvent>data) || this.shouldRender;
case EditorCommon.ViewEventNames.ScrollRequestEvent:
this.shouldRender = this.onCursorScrollRequest(<EditorCommon.IViewScrollRequestEvent>data) || this.shouldRender;
break;
case EditorCommon.EventType.ConfigurationChanged:
......
......@@ -235,8 +235,8 @@ export class ViewModel extends EventEmitter implements EditorCommon.IViewModel {
this.onCursorRevealRange(<EditorCommon.ICursorRevealRangeEvent>data);
break;
case EditorCommon.EventType.CursorLineScroll:
this.onCursorLineScroll(<EditorCommon.ICursorLineScrollEvent>data);
case EditorCommon.EventType.CursorScrollRequest:
this.onCursorScrollRequest(<EditorCommon.ICursorScrollRequestEvent>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
......
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册