提交 e0119398 编写于 作者: S Sandeep Somavarapu

Implement left, right cursor move commands

上级 d4fac8e9
......@@ -1253,15 +1253,23 @@ export class Cursor extends EventEmitter {
}
private _moveLeft(inSelectionMode:boolean, ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.moveLeft(oneCursor, inSelectionMode, oneCtx));
ctx.eventData= ctx.eventData || {};
ctx.eventData.to= editorCommon.CursorMovePosition.Left;
ctx.eventData.select = inSelectionMode;
return this._cursorMove(ctx);
}
private _moveWordLeft(inSelectionMode:boolean, wordNavigationType:WordNavigationType, ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.moveWordLeft(oneCursor, inSelectionMode, wordNavigationType, oneCtx));
}
private _moveRight(inSelectionMode:boolean, ctx: IMultipleCursorOperationContext): boolean {
return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.moveRight(oneCursor, inSelectionMode, oneCtx));
private _moveRight(inSelectionMode: boolean, ctx: IMultipleCursorOperationContext): boolean {
ctx.eventData= ctx.eventData || {};
ctx.eventData.to= editorCommon.CursorMovePosition.Right;
ctx.eventData.select = inSelectionMode;
return this._cursorMove(ctx);
}
private _moveWordRight(inSelectionMode:boolean, wordNavigationType:WordNavigationType, ctx: IMultipleCursorOperationContext): boolean {
......@@ -1272,7 +1280,7 @@ export class Cursor extends EventEmitter {
ctx.eventData= ctx.eventData || {};
ctx.eventData.to= editorCommon.CursorMovePosition.Down;
ctx.eventData.select = inSelectionMode;
ctx.eventData.by= editorCommon.CursorMoveByUnit.WrappedLines;
ctx.eventData.by= editorCommon.CursorMoveByUnit.WrappedLine;
ctx.eventData.isPaged= isPaged;
return this._cursorMove(ctx);
......@@ -1282,7 +1290,7 @@ export class Cursor extends EventEmitter {
ctx.eventData= ctx.eventData || {};
ctx.eventData.to= editorCommon.CursorMovePosition.Up;
ctx.eventData.select= inSelectionMode;
ctx.eventData.by= editorCommon.CursorMoveByUnit.WrappedLines;
ctx.eventData.by= editorCommon.CursorMoveByUnit.WrappedLine;
ctx.eventData.isPaged= isPaged;
return this._cursorMove(ctx);
......
......@@ -581,6 +581,12 @@ export class OneCursor {
public getViewLineCenterColumn(lineNumber:number): number {
return Math.round((this.getViewLineMaxColumn(lineNumber) + this.getViewLineMinColumn(lineNumber)) / 2);
}
public getViewLineSize(lineNumber:number): number {
return this.getViewLineMaxColumn(lineNumber) - this.getViewLineMinColumn(lineNumber);
}
public getViewHalfLineSize(lineNumber:number): number {
return Math.round(this.getViewLineSize(lineNumber) / 2);
}
public getViewLineFirstNonWhiteSpaceColumn(lineNumber:number): number {
return this.viewModelHelper.viewModel.getLineFirstNonWhitespaceColumn(lineNumber);
}
......@@ -677,6 +683,20 @@ export class OneCursorOp {
let noOfLines = moveParams.isPaged ? (moveParams.pageSize || cursor.getPageSize()) : moveParams.amount;
let viewColumn;
switch (moveParams.to) {
case editorCommon.CursorMovePosition.Left:
return this.moveLeft(cursor, inSelectionMode, editorCommon.CursorMoveByUnit.HalfLine === moveParams.by ? cursor.getViewHalfLineSize(viewLineNumber) : moveParams.amount, ctx);
case editorCommon.CursorMovePosition.Right:
return this.moveRight(cursor, inSelectionMode, editorCommon.CursorMoveByUnit.HalfLine === moveParams.by ? cursor.getViewHalfLineSize(viewLineNumber) : moveParams.amount, ctx);
case editorCommon.CursorMovePosition.Up:
if (editorCommon.CursorMoveByUnit.WrappedLine === moveParams.by) {
return this.moveUp(cursor, inSelectionMode, noOfLines, ctx);
}
return false;
case editorCommon.CursorMovePosition.Down:
if (editorCommon.CursorMoveByUnit.WrappedLine === moveParams.by) {
return this.moveDown(cursor, inSelectionMode, noOfLines, ctx);
}
return false;
case editorCommon.CursorMovePosition.WrappedLineStart:
viewColumn = cursor.getViewLineMinColumn(viewLineNumber);
break;
......@@ -692,22 +712,12 @@ export class OneCursorOp {
case editorCommon.CursorMovePosition.WrappedLineLastNonWhitespaceCharacter:
viewColumn = cursor.getViewLineLastNonWhiteSpaceColumn(viewLineNumber);
break;
case editorCommon.CursorMovePosition.Up:
if (editorCommon.CursorMoveByUnit.WrappedLines === moveParams.by) {
return this.moveUp(cursor, inSelectionMode, noOfLines, ctx);
}
return false;
case editorCommon.CursorMovePosition.Down:
if (editorCommon.CursorMoveByUnit.WrappedLines === moveParams.by) {
return this.moveDown(cursor, inSelectionMode, noOfLines, ctx);
}
return false;
case editorCommon.CursorMovePosition.ViewPortTop:
viewLineNumber = cursor.convertModelPositionToViewPosition(cursor.getLineFromViewPortTop(noOfLines), 1).lineNumber;
viewLineNumber = cursor.convertModelPositionToViewPosition(cursor.getLineFromViewPortTop(moveParams.amount), 1).lineNumber;
viewColumn = cursor.getViewLineFirstNonWhiteSpaceColumn(viewLineNumber);
break;
case editorCommon.CursorMovePosition.ViewPortBottom:
viewLineNumber= cursor.convertModelPositionToViewPosition(cursor.getLineFromViewPortBottom(noOfLines), 1).lineNumber;;
viewLineNumber= cursor.convertModelPositionToViewPosition(cursor.getLineFromViewPortBottom(moveParams.amount), 1).lineNumber;;
viewColumn = cursor.getViewLineFirstNonWhiteSpaceColumn(viewLineNumber);
break;
case editorCommon.CursorMovePosition.ViewPortCenter:
......@@ -789,7 +799,7 @@ export class OneCursorOp {
return this._columnSelectOp(cursor, toViewLineNumber, toViewVisualColumn);
}
public static moveLeft(cursor:OneCursor, inSelectionMode: boolean, ctx: IOneCursorOperationContext): boolean {
public static moveLeft(cursor:OneCursor, inSelectionMode: boolean, noOfColumns: number= 1, ctx: IOneCursorOperationContext): boolean {
let viewLineNumber:number,
viewColumn:number;
......@@ -801,7 +811,7 @@ export class OneCursorOp {
viewColumn = viewSelectionStart.column;
} else {
let validatedViewPosition = cursor.getValidViewPosition();
let r = cursor.getLeftOfViewPosition(validatedViewPosition.lineNumber, validatedViewPosition.column);
let r = cursor.getLeftOfViewPosition(validatedViewPosition.lineNumber, validatedViewPosition.column - (noOfColumns - 1));
viewLineNumber = r.lineNumber;
viewColumn = r.column;
}
......@@ -847,7 +857,7 @@ export class OneCursorOp {
return true;
}
public static moveRight(cursor:OneCursor, inSelectionMode: boolean, ctx: IOneCursorOperationContext): boolean {
public static moveRight(cursor:OneCursor, inSelectionMode: boolean, noOfColumns: number= 1, ctx: IOneCursorOperationContext): boolean {
let viewLineNumber:number,
viewColumn:number;
......@@ -859,7 +869,7 @@ export class OneCursorOp {
viewColumn = viewSelectionEnd.column;
} else {
let validatedViewPosition = cursor.getValidViewPosition();
let r = cursor.getRightOfViewPosition(validatedViewPosition.lineNumber, validatedViewPosition.column);
let r = cursor.getRightOfViewPosition(validatedViewPosition.lineNumber, validatedViewPosition.column + (noOfColumns - 1));
viewLineNumber = r.lineNumber;
viewColumn = r.column;
}
......
......@@ -4206,9 +4206,10 @@ export const CursorMovePosition = {
* Units for Cursor move 'by' argument
*/
export const CursorMoveByUnit = {
Lines: 'lines',
WrappedLines: 'wrappedLines',
Characters: 'characters'
Line: 'line',
WrappedLine: 'wrappedLine',
Character: 'character',
HalfLine: 'halfLine'
};
/**
......
......@@ -46,6 +46,78 @@ suite('Cursor move command test', () => {
thisConfiguration.dispose();
});
test('move left should move to left character', () => {
thisCursor= aCursor();
moveTo(thisCursor, 1, 8);
moveLeft(thisCursor);
cursorEqual(thisCursor, 1, 7);
});
test('move left should move to left by n characters', () => {
thisCursor= aCursor();
moveTo(thisCursor, 1, 8);
moveLeft(thisCursor, 3);
cursorEqual(thisCursor, 1, 5);
});
test('move left should move to left by half line', () => {
thisCursor= aCursor();
moveTo(thisCursor, 1, 8);
moveLeft(thisCursor, 1, CursorMoveByUnit.HalfLine);
cursorEqual(thisCursor, 1, 1);
});
test('move left moves to previous line', () => {
thisCursor= aCursor();
moveTo(thisCursor, 2, 3);
moveLeft(thisCursor, 10);
cursorEqual(thisCursor, 1, LINE1.length + 1);
});
test('move right should move to right character', () => {
thisCursor= aCursor();
moveTo(thisCursor, 1, 5);
moveRight(thisCursor);
cursorEqual(thisCursor, 1, 6);
});
test('move right should move to right by n characters', () => {
thisCursor= aCursor();
moveTo(thisCursor, 1, 2);
moveRight(thisCursor, 6);
cursorEqual(thisCursor, 1, 8);
});
test('move right should move to right by half line', () => {
thisCursor= aCursor();
moveTo(thisCursor, 1, 4);
moveRight(thisCursor, 1, CursorMoveByUnit.HalfLine);
cursorEqual(thisCursor, 1, 14);
});
test('move right moves to next line', () => {
thisCursor= aCursor();
moveTo(thisCursor, 1, 8);
moveRight(thisCursor, 100);
cursorEqual(thisCursor, 2, 1);
});
test('move to first character of line from middle', () => {
thisCursor= aCursor();
moveTo(thisCursor, 1, 8);
......@@ -404,12 +476,20 @@ function moveToLineLastNonWhiteSpaceCharacter(cursor: Cursor) {
move(cursor, {to: CursorMovePosition.WrappedLineLastNonWhitespaceCharacter});
}
function moveLeft(cursor: Cursor, amount?: number, by?: string, select?: boolean) {
move(cursor, {to: CursorMovePosition.Left, by:by, amount: amount, select: select});
}
function moveRight(cursor: Cursor, amount?: number, by?: string, select?: boolean) {
move(cursor, {to: CursorMovePosition.Right, by:by, amount: amount, select: select});
}
function moveUp(cursor: Cursor, noOfLines: number= 1, select?: boolean) {
move(cursor, {to: CursorMovePosition.Up, by:CursorMoveByUnit.WrappedLines, amount: noOfLines, select: select});
move(cursor, {to: CursorMovePosition.Up, by:CursorMoveByUnit.WrappedLine, amount: noOfLines, select: select});
}
function moveDown(cursor: Cursor, noOfLines: number= 1, select?: boolean) {
move(cursor, {to: CursorMovePosition.Down, by:CursorMoveByUnit.WrappedLines, amount: noOfLines, select: select});
move(cursor, {to: CursorMovePosition.Down, by:CursorMoveByUnit.WrappedLine, amount: noOfLines, select: select});
}
function moveToTop(cursor: Cursor, noOfLines: number= 1, select?: boolean) {
......
......@@ -3216,9 +3216,10 @@ declare module monaco.editor {
* Units for Cursor move 'by' argument
*/
export const CursorMoveByUnit: {
Lines: string;
WrappedLines: string;
Characters: string;
Line: string;
WrappedLine: string;
Character: string;
HalfLine: string;
};
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册