提交 978065ad 编写于 作者: S Sandeep Somavarapu

Code review

上级 5c28e68b
......@@ -433,8 +433,8 @@ export function createMonacoEditorAPI(): typeof monaco.editor {
// vars
EditorType: editorCommon.EditorType,
CursorMoveViewPosition: editorCommon.CursorMoveViewPosition,
Handler: editorCommon.Handler,
ViewPosition: editorCommon.ViewPosition,
// consts
KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS: editorCommon.KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS,
......
......@@ -944,7 +944,7 @@ export class Cursor extends EventEmitter {
this._handlers[H.JumpToBracket] = (ctx) => this._jumpToBracket(ctx);
this._handlers[H.CursorMove] = (ctx) => this._move(false, ctx);
this._handlers[H.CursorMove] = (ctx) => this._cursorMove(ctx);
this._handlers[H.MoveTo] = (ctx) => this._moveTo(false, ctx);
this._handlers[H.MoveToSelect] = (ctx) => this._moveTo(true, ctx);
this._handlers[H.ColumnSelect] = (ctx) => this._columnSelectMouse(ctx);
......@@ -1093,8 +1093,7 @@ export class Cursor extends EventEmitter {
postOperationRunnable: null,
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false,
requestScrollDeltaLines: 0,
eventData: ctx.eventData
requestScrollDeltaLines: 0
};
result = callable(i, cursors[i], context) || result;
......@@ -1128,8 +1127,8 @@ export class Cursor extends EventEmitter {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.moveTo(oneCursor, inSelectionMode, ctx.eventData.position, ctx.eventData.viewPosition, ctx.eventSource, oneCtx));
}
private _move(inSelectionMode:boolean, ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.move(oneCursor, inSelectionMode, ctx.eventData.to, ctx.eventSource, oneCtx));
private _cursorMove(ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.move(oneCursor, !!ctx.eventData.inSelectionMode, ctx.eventData.to, ctx.eventSource, oneCtx));
}
private _columnSelectToLineNumber: number = 0;
......
......@@ -6,7 +6,7 @@
import {onUnexpectedError, illegalArgument} from 'vs/base/common/errors';
import * as strings from 'vs/base/common/strings';
import types = require('vs/base/common/types');
import * as types from 'vs/base/common/types';
import {ReplaceCommand, ReplaceCommandWithOffsetCursorState, ReplaceCommandWithoutChangingPosition} from 'vs/editor/common/commands/replaceCommand';
import {ShiftCommand} from 'vs/editor/common/commands/shiftCommand';
import {SurroundSelectionCommand} from 'vs/editor/common/commands/surroundSelectionCommand';
......@@ -24,7 +24,6 @@ export interface IPostOperationRunnable {
export interface IOneCursorOperationContext {
cursorPositionChangeReason: editorCommon.CursorChangeReason;
eventData: any;
shouldReveal: boolean;
shouldRevealVerticalInCenter: boolean;
shouldRevealHorizontal: boolean;
......@@ -635,16 +634,16 @@ export class OneCursorOp {
return this.move(cursor, inSelectionMode, validatedViewPosition, eventSource, ctx);
}
public static move(cursor:OneCursor, inSelectionMode: boolean, to:editorCommon.IPosition | string, eventSource: string, ctx: IOneCursorOperationContext): boolean {
public static move(cursor: OneCursor, inSelectionMode: boolean, to: editorCommon.IPosition | string, eventSource: string, ctx: IOneCursorOperationContext): boolean {
if (!to) {
illegalArgument('to');
}
if (types.isString(to)) {
return this._move(cursor, inSelectionMode, to, ctx);
return this.moveToLogicalViewPosition(cursor, inSelectionMode, to, ctx);
}
let viewPosition: editorCommon.IPosition= <editorCommon.IPosition>to;
let viewPosition: editorCommon.IPosition = <editorCommon.IPosition>to;
let reason = (eventSource === 'mouse' ? editorCommon.CursorChangeReason.Explicit : editorCommon.CursorChangeReason.NotSet);
if (eventSource === 'api') {
ctx.shouldRevealVerticalInCenter = true;
......@@ -656,24 +655,24 @@ export class OneCursorOp {
return true;
}
private static _move(cursor:OneCursor, inSelectionMode: boolean, viewPosition:string, ctx: IOneCursorOperationContext): boolean {
private static moveToLogicalViewPosition(cursor: OneCursor, inSelectionMode: boolean, cursorMoveViewPosition: string, ctx: IOneCursorOperationContext): boolean {
let validatedViewPosition = cursor.getValidViewPosition();
let viewLineNumber = validatedViewPosition.lineNumber;
let viewColumn;
switch (viewPosition) {
case editorCommon.ViewPosition.LineStart:
switch (cursorMoveViewPosition) {
case editorCommon.CursorMoveViewPosition.LineStart:
viewColumn = cursor.getViewLineMinColumn(viewLineNumber);
break;
case editorCommon.ViewPosition.LineFirstNonWhitespaceCharacter:
case editorCommon.CursorMoveViewPosition.LineFirstNonWhitespaceCharacter:
viewColumn = cursor.getViewLineFirstNonWhiteSpaceColumn(viewLineNumber);
break;
case editorCommon.ViewPosition.LineCenter:
case editorCommon.CursorMoveViewPosition.LineColumnCenter:
viewColumn = cursor.getViewLineCenterColumn(viewLineNumber);
break;
case editorCommon.ViewPosition.LineEnd:
case editorCommon.CursorMoveViewPosition.LineEnd:
viewColumn = cursor.getViewLineMaxColumn(viewLineNumber);
break;
case editorCommon.ViewPosition.LineLastNonWhitespaceCharacter:
case editorCommon.CursorMoveViewPosition.LineLastNonWhitespaceCharacter:
viewColumn = cursor.getViewLineLastNonWhiteSpaceColumn(viewLineNumber);
break;
default:
......
......@@ -4,11 +4,11 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import nls = require('vs/nls');
import * as nls from 'vs/nls';
import {IAction} from 'vs/base/common/actions';
import {IEventEmitter, BulkListenerCallback} from 'vs/base/common/eventEmitter';
import {MarkedString} from 'vs/base/common/htmlContent';
import types = require('vs/base/common/types');
import * as types from 'vs/base/common/types';
import URI from 'vs/base/common/uri';
import {TPromise} from 'vs/base/common/winjs.base';
import {IInstantiationService, IConstructorSignature1, IConstructorSignature2} from 'vs/platform/instantiation/common/instantiation';
......@@ -4167,12 +4167,12 @@ export var EventType = {
};
/**
* Positions on the view
* Logical positions in the view for cursor move command.
*/
export const ViewPosition = {
export const CursorMoveViewPosition = {
LineStart: 'lineStart',
LineFirstNonWhitespaceCharacter: 'lineFirstNonWhitespaceCharacter',
LineCenter: 'lineCenter',
LineColumnCenter: 'lineColumnCenter',
LineEnd: 'lineEnd',
LineLastNonWhitespaceCharacter: 'lineLastNonWhitespaceCharacter'
};
......@@ -4185,9 +4185,9 @@ export var CommandDescription= {
description: nls.localize('editorCommand.cursorMove.description', "Move cursor to a logical position in the view"),
args: [
{
name: 'Logical position argument',
description: nls.localize('editorCommand.cursorMove.arg.description', "A logical position in the view"),
constraint: (arg) => types.isObject(arg) && types.isString(arg.to)
name: nls.localize('editorCommand.cursorMove.arg.name', "Cursor move argument"),
description: nls.localize('editorCommand.cursorMove.arg.description', "Argument containing mandatory 'to' value and an optional 'inSelectionMode' value. Value of 'to' has to be a defined value in `CursorMoveViewPosition`."),
constraint: (arg) => types.isObject(arg) && types.isString(arg.to) && (types.isUndefined(arg.inSelectionMode) || types.isBoolean(arg.inSelectionMode))
}
]
}
......
......@@ -13,7 +13,7 @@ import {Selection} from 'vs/editor/common/core/selection';
import {
EndOfLinePreference, EventType, Handler, IPosition, ISelection, IEditorOptions,
DefaultEndOfLine, ITextModelCreationOptions, ICommand,
ITokenizedModel, IEditOperationBuilder, ICursorStateComputerData, ViewPosition
ITokenizedModel, IEditOperationBuilder, ICursorStateComputerData, CursorMoveViewPosition
} from 'vs/editor/common/editorCommon';
import {Model} from 'vs/editor/common/model/model';
import {IMode, IndentAction} from 'vs/editor/common/modes';
......@@ -37,23 +37,23 @@ function move(cursor: Cursor, args: any) {
}
function moveToLineStart(cursor: Cursor) {
move(cursor, {to: ViewPosition.LineStart});
move(cursor, {to: CursorMoveViewPosition.LineStart});
}
function moveToLineFirstNonWhiteSpaceCharacter(cursor: Cursor) {
move(cursor, {to: ViewPosition.LineFirstNonWhitespaceCharacter});
move(cursor, {to: CursorMoveViewPosition.LineFirstNonWhitespaceCharacter});
}
function moveToLineCenter(cursor: Cursor) {
move(cursor, {to: ViewPosition.LineCenter});
move(cursor, {to: CursorMoveViewPosition.LineColumnCenter});
}
function moveToLineEnd(cursor: Cursor) {
move(cursor, {to: ViewPosition.LineEnd});
move(cursor, {to: CursorMoveViewPosition.LineEnd});
}
function moveToLineLastNonWhiteSpaceCharacter(cursor: Cursor) {
move(cursor, {to: ViewPosition.LineLastNonWhitespaceCharacter});
move(cursor, {to: CursorMoveViewPosition.LineLastNonWhitespaceCharacter});
}
function moveToPosition(cursor: Cursor, lineNumber: number, column: number) {
......
......@@ -3185,12 +3185,12 @@ declare module monaco.editor {
};
/**
* Positions on the view
* Logical positions in the view for cursor move command.
*/
export const ViewPosition: {
export const CursorMoveViewPosition: {
LineStart: string;
LineFirstNonWhitespaceCharacter: string;
LineCenter: string;
LineColumnCenter: string;
LineEnd: string;
LineLastNonWhitespaceCharacter: string;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册