diff --git a/src/vs/editor/browser/editor.all.ts b/src/vs/editor/browser/editor.all.ts index 0b200fdd95cb4978047367af16119a380f217fc2..c2b735ef185fd8022c3418fe6325c262ab293752 100644 --- a/src/vs/editor/browser/editor.all.ts +++ b/src/vs/editor/browser/editor.all.ts @@ -17,12 +17,13 @@ import 'vs/editor/contrib/codelens/browser/codelens'; import 'vs/editor/contrib/comment/common/comment'; import 'vs/editor/contrib/contextmenu/browser/contextmenu'; import 'vs/editor/contrib/diffNavigator/common/diffNavigator'; +import 'vs/editor/contrib/dnd/browser/dnd'; import 'vs/editor/contrib/find/browser/find'; +import 'vs/editor/contrib/folding/browser/folding'; import 'vs/editor/contrib/format/browser/formatActions'; import 'vs/editor/contrib/goToDeclaration/browser/goToDeclaration'; import 'vs/editor/contrib/gotoError/browser/gotoError'; import 'vs/editor/contrib/hover/browser/hover'; -import 'vs/editor/contrib/dnd/browser/dnd'; import 'vs/css!vs/editor/contrib/inPlaceReplace/browser/inPlaceReplace'; import 'vs/editor/contrib/inPlaceReplace/common/inPlaceReplace'; import 'vs/editor/contrib/iPadShowKeyboard/browser/iPadShowKeyboard'; @@ -40,4 +41,4 @@ import 'vs/editor/contrib/snippet/browser/snippet'; import 'vs/editor/contrib/suggest/browser/suggestController'; import 'vs/editor/contrib/toggleTabFocusMode/common/toggleTabFocusMode'; import 'vs/editor/contrib/wordHighlighter/common/wordHighlighter'; -import 'vs/editor/contrib/folding/browser/folding'; +import 'vs/editor/contrib/wordOperations/common/wordOperations'; diff --git a/src/vs/editor/common/config/config.ts b/src/vs/editor/common/config/config.ts index fe85af9603a6b79d2645fd4e33a4e90b36efd414..b8562dc4d2d0a4b095a93d5918243db6b47b1826 100644 --- a/src/vs/editor/common/config/config.ts +++ b/src/vs/editor/common/config/config.ts @@ -95,7 +95,7 @@ export abstract class EditorCommand extends Command { this._callback = opts.handler; } - protected runEditorCommand(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor, args: any): void { + public runEditorCommand(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor, args: any): void { let controller = controllerGetter(editor); if (controller) { this._callback(controllerGetter(editor)); @@ -128,7 +128,7 @@ export abstract class EditorCommand extends Command { }); } - protected abstract runEditorCommand(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor, args: any): void | TPromise; + public abstract runEditorCommand(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor, args: any): void | TPromise; } export function findFocusedEditor(commandId: string, accessor: ServicesAccessor, complain: boolean): editorCommon.ICommonCodeEditor { @@ -602,23 +602,6 @@ registerCommand(new CoreCommand({ } })); - -registerCommand(new WordCommand(H.CursorWordStartLeft, false, KeyCode.LeftArrow)); -registerCommand(new UnboundCoreCommand(H.CursorWordEndLeft)); -registerCommand(new UnboundCoreCommand(H.CursorWordLeft)); - -registerCommand(new WordCommand(H.CursorWordStartLeftSelect, true, KeyCode.LeftArrow)); -registerCommand(new UnboundCoreCommand(H.CursorWordEndLeftSelect)); -registerCommand(new UnboundCoreCommand(H.CursorWordLeftSelect)); - -registerCommand(new WordCommand(H.CursorWordEndRight, false, KeyCode.RightArrow)); -registerCommand(new UnboundCoreCommand(H.CursorWordStartRight)); -registerCommand(new UnboundCoreCommand(H.CursorWordRight)); - -registerCommand(new WordCommand(H.CursorWordEndRightSelect, true, KeyCode.RightArrow)); -registerCommand(new UnboundCoreCommand(H.CursorWordStartRightSelect)); -registerCommand(new UnboundCoreCommand(H.CursorWordRightSelect)); - registerCommand(new WordCommand(H.DeleteWordLeft, false, KeyCode.Backspace, EditorContextKeys.Writable)); registerCommand(new UnboundCoreCommand(H.DeleteWordStartLeft, EditorContextKeys.Writable)); registerCommand(new UnboundCoreCommand(H.DeleteWordEndLeft, EditorContextKeys.Writable)); diff --git a/src/vs/editor/common/controller/cursor.ts b/src/vs/editor/common/controller/cursor.ts index 80710728d6dc6e0adec102c9658320fd5b6029f1..811139848cc34c5ff35a8fe7aeaa7411eb28e39b 100644 --- a/src/vs/editor/common/controller/cursor.ts +++ b/src/vs/editor/common/controller/cursor.ts @@ -892,25 +892,9 @@ export class Cursor extends EventEmitter { this._handlers[H.CursorLeft] = (ctx) => this._moveLeft(false, ctx); this._handlers[H.CursorLeftSelect] = (ctx) => this._moveLeft(true, ctx); - this._handlers[H.CursorWordLeft] = (ctx) => this._moveWordLeft(false, WordNavigationType.WordStart, ctx); - this._handlers[H.CursorWordStartLeft] = (ctx) => this._moveWordLeft(false, WordNavigationType.WordStart, ctx); - this._handlers[H.CursorWordEndLeft] = (ctx) => this._moveWordLeft(false, WordNavigationType.WordEnd, ctx); - - this._handlers[H.CursorWordLeftSelect] = (ctx) => this._moveWordLeft(true, WordNavigationType.WordStart, ctx); - this._handlers[H.CursorWordStartLeftSelect] = (ctx) => this._moveWordLeft(true, WordNavigationType.WordStart, ctx); - this._handlers[H.CursorWordEndLeftSelect] = (ctx) => this._moveWordLeft(true, WordNavigationType.WordEnd, ctx); - this._handlers[H.CursorRight] = (ctx) => this._moveRight(false, ctx); this._handlers[H.CursorRightSelect] = (ctx) => this._moveRight(true, ctx); - this._handlers[H.CursorWordRight] = (ctx) => this._moveWordRight(false, WordNavigationType.WordEnd, ctx); - this._handlers[H.CursorWordStartRight] = (ctx) => this._moveWordRight(false, WordNavigationType.WordStart, ctx); - this._handlers[H.CursorWordEndRight] = (ctx) => this._moveWordRight(false, WordNavigationType.WordEnd, ctx); - - this._handlers[H.CursorWordRightSelect] = (ctx) => this._moveWordRight(true, WordNavigationType.WordEnd, ctx); - this._handlers[H.CursorWordStartRightSelect] = (ctx) => this._moveWordRight(true, WordNavigationType.WordStart, ctx); - this._handlers[H.CursorWordEndRightSelect] = (ctx) => this._moveWordRight(true, WordNavigationType.WordEnd, ctx); - this._handlers[H.CursorUp] = (ctx) => this._moveUp(false, false, ctx); this._handlers[H.CursorUpSelect] = (ctx) => this._moveUp(true, false, ctx); this._handlers[H.CursorDown] = (ctx) => this._moveDown(false, false, ctx); @@ -1227,10 +1211,6 @@ export class Cursor extends EventEmitter { 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 { ctx.eventData = ctx.eventData || {}; ctx.eventData.to = editorCommon.CursorMovePosition.Right; @@ -1239,10 +1219,6 @@ export class Cursor extends EventEmitter { return this._cursorMove(ctx); } - private _moveWordRight(inSelectionMode: boolean, wordNavigationType: WordNavigationType, ctx: IMultipleCursorOperationContext): boolean { - return this._invokeForAll(ctx, (cursorIndex: number, oneCursor: OneCursor, oneCtx: IOneCursorOperationContext) => OneCursorOp.moveWordRight(oneCursor, inSelectionMode, wordNavigationType, oneCtx)); - } - private _moveDown(inSelectionMode: boolean, isPaged: boolean, ctx: IMultipleCursorOperationContext): boolean { ctx.eventData = ctx.eventData || {}; ctx.eventData.to = editorCommon.CursorMovePosition.Down; diff --git a/src/vs/editor/common/controller/cursorWordOperations.ts b/src/vs/editor/common/controller/cursorWordOperations.ts index 36535f8284144c6a7819ae3e6c0fda2562470556..aa70ac7b82c672e846e58b0f8b70c4a44dec03d6 100644 --- a/src/vs/editor/common/controller/cursorWordOperations.ts +++ b/src/vs/editor/common/controller/cursorWordOperations.ts @@ -36,7 +36,7 @@ export const enum WordType { Separator = 2 } -const enum CharacterClass { +export const enum WordCharacterClass { Regular = 0, Whitespace = 1, WordSeparator = 2 @@ -47,17 +47,17 @@ export const enum WordNavigationType { WordEnd = 1 } -class WordCharacterClassifier extends CharacterClassifier { +export class WordCharacterClassifier extends CharacterClassifier { constructor(wordSeparators: string) { - super(CharacterClass.Regular); + super(WordCharacterClass.Regular); for (let i = 0, len = wordSeparators.length; i < len; i++) { - this.set(wordSeparators.charCodeAt(i), CharacterClass.WordSeparator); + this.set(wordSeparators.charCodeAt(i), WordCharacterClass.WordSeparator); } - this.set(CharCode.Space, CharacterClass.Whitespace); - this.set(CharCode.Tab, CharacterClass.Whitespace); + this.set(CharCode.Space, WordCharacterClass.Whitespace); + this.set(CharCode.Tab, WordCharacterClass.Whitespace); } } @@ -72,7 +72,7 @@ function once(computeFn: (input: string) => R): (input: string) => R { }; } -let getMapForWordSeparators = once( +export const getMapForWordSeparators = once( (input) => new WordCharacterClassifier(input) ); @@ -94,17 +94,17 @@ export class WordOperations { let chCode = lineContent.charCodeAt(chIndex); let chClass = wordSeparators.get(chCode); - if (chClass === CharacterClass.Regular) { + if (chClass === WordCharacterClass.Regular) { if (wordType === WordType.Separator) { return this._createWord(lineContent, wordType, chIndex + 1, this._findEndOfWord(lineContent, wordSeparators, wordType, chIndex + 1)); } wordType = WordType.Regular; - } else if (chClass === CharacterClass.WordSeparator) { + } else if (chClass === WordCharacterClass.WordSeparator) { if (wordType === WordType.Regular) { return this._createWord(lineContent, wordType, chIndex + 1, this._findEndOfWord(lineContent, wordSeparators, wordType, chIndex + 1)); } wordType = WordType.Separator; - } else if (chClass === CharacterClass.Whitespace) { + } else if (chClass === WordCharacterClass.Whitespace) { if (wordType !== WordType.None) { return this._createWord(lineContent, wordType, chIndex + 1, this._findEndOfWord(lineContent, wordSeparators, wordType, chIndex + 1)); } @@ -124,13 +124,13 @@ export class WordOperations { let chCode = lineContent.charCodeAt(chIndex); let chClass = wordSeparators.get(chCode); - if (chClass === CharacterClass.Whitespace) { + if (chClass === WordCharacterClass.Whitespace) { return chIndex; } - if (wordType === WordType.Regular && chClass === CharacterClass.WordSeparator) { + if (wordType === WordType.Regular && chClass === WordCharacterClass.WordSeparator) { return chIndex; } - if (wordType === WordType.Separator && chClass === CharacterClass.Regular) { + if (wordType === WordType.Separator && chClass === WordCharacterClass.Regular) { return chIndex; } } @@ -150,17 +150,17 @@ export class WordOperations { let chCode = lineContent.charCodeAt(chIndex); let chClass = wordSeparators.get(chCode); - if (chClass === CharacterClass.Regular) { + if (chClass === WordCharacterClass.Regular) { if (wordType === WordType.Separator) { return this._createWord(lineContent, wordType, this._findStartOfWord(lineContent, wordSeparators, wordType, chIndex - 1), chIndex); } wordType = WordType.Regular; - } else if (chClass === CharacterClass.WordSeparator) { + } else if (chClass === WordCharacterClass.WordSeparator) { if (wordType === WordType.Regular) { return this._createWord(lineContent, wordType, this._findStartOfWord(lineContent, wordSeparators, wordType, chIndex - 1), chIndex); } wordType = WordType.Separator; - } else if (chClass === CharacterClass.Whitespace) { + } else if (chClass === WordCharacterClass.Whitespace) { if (wordType !== WordType.None) { return this._createWord(lineContent, wordType, this._findStartOfWord(lineContent, wordSeparators, wordType, chIndex - 1), chIndex); } @@ -179,20 +179,20 @@ export class WordOperations { let chCode = lineContent.charCodeAt(chIndex); let chClass = wordSeparators.get(chCode); - if (chClass === CharacterClass.Whitespace) { + if (chClass === WordCharacterClass.Whitespace) { return chIndex + 1; } - if (wordType === WordType.Regular && chClass === CharacterClass.WordSeparator) { + if (wordType === WordType.Regular && chClass === WordCharacterClass.WordSeparator) { return chIndex + 1; } - if (wordType === WordType.Separator && chClass === CharacterClass.Regular) { + if (wordType === WordType.Separator && chClass === WordCharacterClass.Regular) { return chIndex + 1; } } return 0; } - private static _moveWordLeft(wordSeparators: WordCharacterClassifier, model: ICursorSimpleModel, position: Position, wordNavigationType: WordNavigationType): Position { + public static moveWordLeft(wordSeparators: WordCharacterClassifier, model: ICursorSimpleModel, position: Position, wordNavigationType: WordNavigationType): Position { let lineNumber = position.lineNumber; let column = position.column; @@ -225,13 +225,7 @@ export class WordOperations { return new Position(lineNumber, column); } - public static moveWordLeft(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean, wordNavigationType: WordNavigationType): SingleMoveOperationResult { - const wordSeparators = getMapForWordSeparators(config.wordSeparators); - const position = this._moveWordLeft(wordSeparators, model, cursor.position, wordNavigationType); - return SingleMoveOperationResult.fromMove(cursor, inSelectionMode, position.lineNumber, position.column, 0, true, CursorChangeReason.Explicit); - } - - private static _moveWordRight(wordSeparators: WordCharacterClassifier, model: ICursorSimpleModel, position: Position, wordNavigationType: WordNavigationType): Position { + public static moveWordRight(wordSeparators: WordCharacterClassifier, model: ICursorSimpleModel, position: Position, wordNavigationType: WordNavigationType): Position { let lineNumber = position.lineNumber; let column = position.column; @@ -264,12 +258,6 @@ export class WordOperations { return new Position(lineNumber, column); } - public static moveWordRight(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean, wordNavigationType: WordNavigationType): SingleMoveOperationResult { - const wordSeparators = getMapForWordSeparators(config.wordSeparators); - const position = this._moveWordRight(wordSeparators, model, cursor.position, wordNavigationType); - return SingleMoveOperationResult.fromMove(cursor, inSelectionMode, position.lineNumber, position.column, 0, true, CursorChangeReason.Explicit); - } - private static _deleteWordLeftWhitespace(model: ICursorSimpleModel, position: Position): Range { const lineContent = model.getLineContent(position.lineNumber); const startIndex = position.column - 2; diff --git a/src/vs/editor/common/controller/oneCursor.ts b/src/vs/editor/common/controller/oneCursor.ts index 877dca6350cef1f5e4ab34067332d519a1a8c621..3dd381c39b15366cb4bf114351f46f8e11744331 100644 --- a/src/vs/editor/common/controller/oneCursor.ts +++ b/src/vs/editor/common/controller/oneCursor.ts @@ -12,7 +12,7 @@ import { Selection, SelectionDirection } from 'vs/editor/common/core/selection'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { IDisposable } from 'vs/base/common/lifecycle'; import { MoveOperations, SingleMoveOperationResult } from 'vs/editor/common/controller/cursorMoveOperations'; -import { WordOperations, WordNavigationType } from 'vs/editor/common/controller/cursorWordOperations'; +import { WordOperations } from 'vs/editor/common/controller/cursorWordOperations'; import { ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel'; export interface IOneCursorOperationContext { @@ -616,13 +616,6 @@ export class OneCursorOp { ); } - public static moveWordLeft(cursor: OneCursor, inSelectionMode: boolean, wordNavigationType: WordNavigationType, ctx: IOneCursorOperationContext): boolean { - return this._applyMoveOperationResult( - cursor, ctx, - this._fromModelCursorState(cursor, WordOperations.moveWordLeft(cursor.config, cursor.model, cursor.modelState, inSelectionMode, wordNavigationType)) - ); - } - private static _moveRight(cursor: OneCursor, inSelectionMode: boolean, noOfColumns: number = 1, ctx: IOneCursorOperationContext): boolean { return this._applyMoveOperationResult( cursor, ctx, @@ -630,13 +623,6 @@ export class OneCursorOp { ); } - public static moveWordRight(cursor: OneCursor, inSelectionMode: boolean, wordNavigationType: WordNavigationType, ctx: IOneCursorOperationContext): boolean { - return this._applyMoveOperationResult( - cursor, ctx, - this._fromModelCursorState(cursor, WordOperations.moveWordRight(cursor.config, cursor.model, cursor.modelState, inSelectionMode, wordNavigationType)) - ); - } - private static _moveDown(cursor: OneCursor, moveArguments: CursorMoveArguments, ctx: IOneCursorOperationContext): boolean { let linesCount = (moveArguments.isPaged ? (moveArguments.pageSize || cursor.config.pageSize) : moveArguments.value) || 1; if (editorCommon.CursorMoveByUnit.WrappedLine === moveArguments.by) { diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 3390af3d04a5468f5053208c66cf508c5635fd24..eba8b91d23d8bace40b4327e8786c192d90784aa 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -4381,25 +4381,9 @@ export var Handler = { CursorLeft: 'cursorLeft', CursorLeftSelect: 'cursorLeftSelect', - CursorWordLeft: 'cursorWordLeft', - CursorWordStartLeft: 'cursorWordStartLeft', - CursorWordEndLeft: 'cursorWordEndLeft', - - CursorWordLeftSelect: 'cursorWordLeftSelect', - CursorWordStartLeftSelect: 'cursorWordStartLeftSelect', - CursorWordEndLeftSelect: 'cursorWordEndLeftSelect', - CursorRight: 'cursorRight', CursorRightSelect: 'cursorRightSelect', - CursorWordRight: 'cursorWordRight', - CursorWordStartRight: 'cursorWordStartRight', - CursorWordEndRight: 'cursorWordEndRight', - - CursorWordRightSelect: 'cursorWordRightSelect', - CursorWordStartRightSelect: 'cursorWordStartRightSelect', - CursorWordEndRightSelect: 'cursorWordEndRightSelect', - CursorUp: 'cursorUp', CursorUpSelect: 'cursorUpSelect', CursorDown: 'cursorDown', diff --git a/src/vs/editor/common/editorCommonExtensions.ts b/src/vs/editor/common/editorCommonExtensions.ts index 6278efb34614f684cc0ac637c7f53d22d032f00e..b2cda70f26a8567e60f373c80e9d853579f04251 100644 --- a/src/vs/editor/common/editorCommonExtensions.ts +++ b/src/vs/editor/common/editorCommonExtensions.ts @@ -95,6 +95,10 @@ export function editorAction(ctor: { new (): EditorAction; }): void { CommonEditorRegistry.registerEditorAction(new ctor()); } +export function editorCommand(ctor: { new (): ConfigEditorCommand }): void { + CommonEditorRegistry.registerEditorCommand(new ctor()); +} + export function commonEditorContribution(ctor: editorCommon.ICommonEditorContributionCtor): void { EditorContributionRegistry.INSTANCE.registerEditorContribution(ctor); } diff --git a/src/vs/editor/contrib/wordOperations/common/wordOperations.ts b/src/vs/editor/contrib/wordOperations/common/wordOperations.ts new file mode 100644 index 0000000000000000000000000000000000000000..3d6cf5addaa87d30f7eb132549e56a8a003eb24c --- /dev/null +++ b/src/vs/editor/contrib/wordOperations/common/wordOperations.ts @@ -0,0 +1,243 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; +import { EditorContextKeys, ICommonCodeEditor, IModel } from 'vs/editor/common/editorCommon'; +import { Selection } from 'vs/editor/common/core/selection'; +import { editorCommand, ServicesAccessor, EditorCommand, ICommandOptions } from 'vs/editor/common/editorCommonExtensions'; +import { Position } from 'vs/editor/common/core/position'; +import { WordNavigationType, WordOperations, getMapForWordSeparators, WordCharacterClassifier } from 'vs/editor/common/controller/cursorWordOperations'; + +export interface MoveWordOptions extends ICommandOptions { + inSelectionMode: boolean; + wordNavigationType: WordNavigationType; +} + +export abstract class WordCommand extends EditorCommand { + + private readonly _inSelectionMode: boolean; + private readonly _wordNavigationType: WordNavigationType; + + constructor(opts: MoveWordOptions) { + super(opts); + this._inSelectionMode = opts.inSelectionMode; + this._wordNavigationType = opts.wordNavigationType; + } + + public runEditorCommand(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void { + const config = editor.getConfiguration(); + const wordSeparators = getMapForWordSeparators(config.wordSeparators); + const model = editor.getModel(); + const selections = editor.getSelections(); + + const result = selections.map((sel) => { + const inPosition = new Position(sel.positionLineNumber, sel.positionColumn); + const outPosition = this._move(wordSeparators, model, inPosition, this._wordNavigationType); + return move(sel, outPosition, this._inSelectionMode); + }); + + editor.setSelections(result); + } + + protected abstract _move(wordSeparators: WordCharacterClassifier, model: IModel, position: Position, wordNavigationType: WordNavigationType): Position; +} + +export class WordLeftCommand extends WordCommand { + protected _move(wordSeparators: WordCharacterClassifier, model: IModel, position: Position, wordNavigationType: WordNavigationType): Position { + return WordOperations.moveWordLeft(wordSeparators, model, position, wordNavigationType); + } +} + +export class WordRightCommand extends WordCommand { + protected _move(wordSeparators: WordCharacterClassifier, model: IModel, position: Position, wordNavigationType: WordNavigationType): Position { + return WordOperations.moveWordRight(wordSeparators, model, position, wordNavigationType); + } +} + +@editorCommand +export class CursorWordStartLeft extends WordLeftCommand { + constructor() { + super({ + inSelectionMode: false, + wordNavigationType: WordNavigationType.WordStart, + id: 'cursorWordStartLeft', + precondition: null, + kbOpts: { + kbExpr: EditorContextKeys.TextFocus, + primary: KeyMod.CtrlCmd | KeyCode.LeftArrow, + mac: { primary: KeyMod.Alt | KeyCode.LeftArrow } + } + }); + } +} + +@editorCommand +export class CursorWordEndLeft extends WordLeftCommand { + constructor() { + super({ + inSelectionMode: false, + wordNavigationType: WordNavigationType.WordEnd, + id: 'cursorWordEndLeft', + precondition: null + }); + } +} + +@editorCommand +export class CursorWordLeft extends WordLeftCommand { + constructor() { + super({ + inSelectionMode: false, + wordNavigationType: WordNavigationType.WordStart, + id: 'cursorWordLeft', + precondition: null + }); + } +} + +@editorCommand +export class CursorWordStartLeftSelect extends WordLeftCommand { + constructor() { + super({ + inSelectionMode: true, + wordNavigationType: WordNavigationType.WordStart, + id: 'cursorWordStartLeftSelect', + precondition: null, + kbOpts: { + kbExpr: EditorContextKeys.TextFocus, + primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.LeftArrow, + mac: { primary: KeyMod.Alt | KeyMod.Shift | KeyCode.LeftArrow } + } + }); + } +} + +@editorCommand +export class CursorWordEndLeftSelect extends WordLeftCommand { + constructor() { + super({ + inSelectionMode: true, + wordNavigationType: WordNavigationType.WordEnd, + id: 'cursorWordEndLeftSelect', + precondition: null + }); + } +} + +@editorCommand +export class CursorWordLeftSelect extends WordLeftCommand { + constructor() { + super({ + inSelectionMode: true, + wordNavigationType: WordNavigationType.WordStart, + id: 'cursorWordLeftSelect', + precondition: null + }); + } +} + +@editorCommand +export class CursorWordStartRight extends WordRightCommand { + constructor() { + super({ + inSelectionMode: false, + wordNavigationType: WordNavigationType.WordStart, + id: 'cursorWordStartRight', + precondition: null + }); + } +} + +@editorCommand +export class CursorWordEndRight extends WordRightCommand { + constructor() { + super({ + inSelectionMode: false, + wordNavigationType: WordNavigationType.WordEnd, + id: 'cursorWordEndRight', + precondition: null, + kbOpts: { + kbExpr: EditorContextKeys.TextFocus, + primary: KeyMod.CtrlCmd | KeyCode.RightArrow, + mac: { primary: KeyMod.Alt | KeyCode.RightArrow } + } + }); + } +} + +@editorCommand +export class CursorWordRight extends WordRightCommand { + constructor() { + super({ + inSelectionMode: false, + wordNavigationType: WordNavigationType.WordEnd, + id: 'cursorWordRight', + precondition: null + }); + } +} + +@editorCommand +export class CursorWordStartRightSelect extends WordRightCommand { + constructor() { + super({ + inSelectionMode: true, + wordNavigationType: WordNavigationType.WordStart, + id: 'cursorWordStartRightSelect', + precondition: null + }); + } +} + +@editorCommand +export class CursorWordEndRightSelect extends WordRightCommand { + constructor() { + super({ + inSelectionMode: true, + wordNavigationType: WordNavigationType.WordEnd, + id: 'cursorWordEndRightSelect', + precondition: null, + kbOpts: { + kbExpr: EditorContextKeys.TextFocus, + primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.RightArrow, + mac: { primary: KeyMod.Alt | KeyMod.Shift | KeyCode.RightArrow } + } + }); + } +} + +@editorCommand +export class CursorWordRightSelect extends WordRightCommand { + constructor() { + super({ + inSelectionMode: true, + wordNavigationType: WordNavigationType.WordEnd, + id: 'cursorWordRightSelect', + precondition: null + }); + } +} + +function move(from: Selection, to: Position, inSelectionMode: boolean): Selection { + if (inSelectionMode) { + // move just position + return new Selection( + from.selectionStartLineNumber, + from.selectionStartColumn, + to.lineNumber, + to.column + ); + } else { + // move everything + return new Selection( + to.lineNumber, + to.column, + to.lineNumber, + to.column + ); + } +} diff --git a/src/vs/editor/contrib/wordOperations/test/common/wordOperations.test.ts b/src/vs/editor/contrib/wordOperations/test/common/wordOperations.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..55cef1a7dcf7ba9c813786ce82aa72482bd40f0a --- /dev/null +++ b/src/vs/editor/contrib/wordOperations/test/common/wordOperations.test.ts @@ -0,0 +1,306 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import * as assert from 'assert'; +import { Position } from 'vs/editor/common/core/position'; +import { Selection } from 'vs/editor/common/core/selection'; +import { ICommonCodeEditor } from 'vs/editor/common/editorCommon'; +import { withMockCodeEditor } from 'vs/editor/test/common/mocks/mockCodeEditor'; +import { + CursorWordLeft, CursorWordLeftSelect, CursorWordStartLeft, + CursorWordEndLeft, CursorWordStartLeftSelect, CursorWordEndLeftSelect, + CursorWordStartRight, CursorWordEndRight, CursorWordRight, + CursorWordStartRightSelect, CursorWordEndRightSelect, CursorWordRightSelect +} from 'vs/editor/contrib/wordOperations/common/wordOperations'; +import { EditorCommand } from 'vs/editor/common/config/config'; + +suite('WordOperations', () => { + + const _cursorWordStartLeft = new CursorWordStartLeft(); + const _cursorWordEndLeft = new CursorWordEndLeft(); + const _cursorWordLeft = new CursorWordLeft(); + const _cursorWordStartLeftSelect = new CursorWordStartLeftSelect(); + const _cursorWordEndLeftSelect = new CursorWordEndLeftSelect(); + const _cursorWordLeftSelect = new CursorWordLeftSelect(); + const _cursorWordStartRight = new CursorWordStartRight(); + const _cursorWordEndRight = new CursorWordEndRight(); + const _cursorWordRight = new CursorWordRight(); + const _cursorWordStartRightSelect = new CursorWordStartRightSelect(); + const _cursorWordEndRightSelect = new CursorWordEndRightSelect(); + const _cursorWordRightSelect = new CursorWordRightSelect(); + + function runEditorCommand(editor: ICommonCodeEditor, command: EditorCommand): void { + command.runEditorCommand(null, editor, null); + } + function moveWordLeft(editor: ICommonCodeEditor, inSelectionMode: boolean = false): void { + runEditorCommand(editor, inSelectionMode ? _cursorWordLeftSelect : _cursorWordLeft); + } + function moveWordStartLeft(editor: ICommonCodeEditor, inSelectionMode: boolean = false): void { + runEditorCommand(editor, inSelectionMode ? _cursorWordStartLeftSelect : _cursorWordStartLeft); + } + function moveWordEndLeft(editor: ICommonCodeEditor, inSelectionMode: boolean = false): void { + runEditorCommand(editor, inSelectionMode ? _cursorWordEndLeftSelect : _cursorWordEndLeft); + } + function moveWordRight(editor: ICommonCodeEditor, inSelectionMode: boolean = false): void { + runEditorCommand(editor, inSelectionMode ? _cursorWordRightSelect : _cursorWordRight); + } + function moveWordEndRight(editor: ICommonCodeEditor, inSelectionMode: boolean = false): void { + runEditorCommand(editor, inSelectionMode ? _cursorWordEndRightSelect : _cursorWordEndRight); + } + function moveWordStartRight(editor: ICommonCodeEditor, inSelectionMode: boolean = false): void { + runEditorCommand(editor, inSelectionMode ? _cursorWordStartRightSelect : _cursorWordStartRight); + } + + test('move word left', () => { + withMockCodeEditor([ + ' \tMy First Line\t ', + '\tMy Second Line', + ' Third Line🐶', + '', + '1', + ], {}, (editor, _) => { + editor.setPosition(new Position(5, 2)); + const expectedStops = [ + [5, 1], + [4, 1], + [3, 11], + [3, 5], + [3, 1], + [2, 12], + [2, 5], + [2, 2], + [2, 1], + [1, 15], + [1, 9], + [1, 6], + [1, 1], + [1, 1], + ]; + + let actualStops: number[][] = []; + for (let i = 0; i < expectedStops.length; i++) { + moveWordLeft(editor); + const pos = editor.getPosition(); + actualStops.push([pos.lineNumber, pos.column]); + } + + assert.deepEqual(actualStops, expectedStops); + }); + }); + + test('move word left selection', () => { + withMockCodeEditor([ + ' \tMy First Line\t ', + '\tMy Second Line', + ' Third Line🐶', + '', + '1', + ], {}, (editor, _) => { + editor.setPosition(new Position(5, 2)); + moveWordLeft(editor, true); + assert.deepEqual(editor.getSelection(), new Selection(5, 2, 5, 1)); + }); + }); + + test('issue #832: moveWordLeft', () => { + withMockCodeEditor([ + ' /* Just some more text a+= 3 +5-3 + 7 */ ' + ], {}, (editor, _) => { + editor.setPosition(new Position(1, 50)); + + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 '.length + 1, '001'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + '.length + 1, '002'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 '.length + 1, '003'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '004'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '005'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '006'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 '.length + 1, '007'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= '.length + 1, '008'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a'.length + 1, '009'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text '.length + 1, '010'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more '.length + 1, '011'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some '.length + 1, '012'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* Just '.length + 1, '013'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' /* '.length + 1, '014'); + moveWordLeft(editor); assert.equal(editor.getPosition().column, ' '.length + 1, '015'); + }); + }); + + test('moveWordStartLeft', () => { + withMockCodeEditor([ + ' /* Just some more text a+= 3 +5-3 + 7 */ ' + ], {}, (editor, _) => { + editor.setPosition(new Position(1, 50)); + + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 '.length + 1, '001'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + '.length + 1, '002'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 '.length + 1, '003'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '004'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '005'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '006'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 '.length + 1, '007'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= '.length + 1, '008'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a'.length + 1, '009'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text '.length + 1, '010'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more '.length + 1, '011'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some '.length + 1, '012'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* Just '.length + 1, '013'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' /* '.length + 1, '014'); + moveWordStartLeft(editor); assert.equal(editor.getPosition().column, ' '.length + 1, '015'); + }); + }); + + test('moveWordEndLeft', () => { + withMockCodeEditor([ + ' /* Just some more text a+= 3 +5-3 + 7 */ ' + ], {}, (editor, _) => { + editor.setPosition(new Position(1, 50)); + + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */'.length + 1, '001'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7'.length + 1, '002'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 +'.length + 1, '003'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3'.length + 1, '004'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '005'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '006'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '007'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3'.length + 1, '008'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+='.length + 1, '009'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a'.length + 1, '010'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more text'.length + 1, '011'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some more'.length + 1, '012'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just some'.length + 1, '013'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /* Just'.length + 1, '014'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ' /*'.length + 1, '015'); + moveWordEndLeft(editor); assert.equal(editor.getPosition().column, ''.length + 1, '016'); + }); + }); + + test('move word right', () => { + withMockCodeEditor([ + ' \tMy First Line\t ', + '\tMy Second Line', + ' Third Line🐶', + '', + '1', + ], {}, (editor, _) => { + editor.setPosition(new Position(1, 1)); + let expectedStops = [ + [1, 8], + [1, 14], + [1, 19], + [1, 21], + [2, 4], + [2, 11], + [2, 16], + [3, 10], + [3, 17], + [4, 1], + [5, 2], + [5, 2], + ]; + + let actualStops: number[][] = []; + for (let i = 0; i < expectedStops.length; i++) { + moveWordRight(editor); + let pos = editor.getPosition(); + actualStops.push([pos.lineNumber, pos.column]); + } + + assert.deepEqual(actualStops, expectedStops); + }); + }); + + test('move word right selection', () => { + withMockCodeEditor([ + ' \tMy First Line\t ', + '\tMy Second Line', + ' Third Line🐶', + '', + '1', + ], {}, (editor, _) => { + editor.setPosition(new Position(1, 1)); + moveWordRight(editor, true); + assert.deepEqual(editor.getSelection(), new Selection(1, 1, 1, 8)); + }); + }); + + test('issue #832: moveWordRight', () => { + withMockCodeEditor([ + ' /* Just some more text a+= 3 +5-3 + 7 */ ' + ], {}, (editor, _) => { + editor.setPosition(new Position(1, 1)); + + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /*'.length + 1, '001'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just'.length + 1, '003'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some'.length + 1, '004'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more'.length + 1, '005'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text'.length + 1, '006'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a'.length + 1, '007'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+='.length + 1, '008'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3'.length + 1, '009'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '010'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '011'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '012'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3'.length + 1, '013'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 +'.length + 1, '014'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7'.length + 1, '015'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */'.length + 1, '016'); + moveWordRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */ '.length + 1, '016'); + + }); + }); + + test('moveWordEndRight', () => { + withMockCodeEditor([ + ' /* Just some more text a+= 3 +5-3 + 7 */ ' + ], {}, (editor, _) => { + editor.setPosition(new Position(1, 1)); + + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /*'.length + 1, '001'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just'.length + 1, '003'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some'.length + 1, '004'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more'.length + 1, '005'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text'.length + 1, '006'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a'.length + 1, '007'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+='.length + 1, '008'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3'.length + 1, '009'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '010'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '011'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '012'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3'.length + 1, '013'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 +'.length + 1, '014'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7'.length + 1, '015'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */'.length + 1, '016'); + moveWordEndRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */ '.length + 1, '016'); + + }); + }); + + test('moveWordStartRight', () => { + withMockCodeEditor([ + ' /* Just some more text a+= 3 +5-3 + 7 */ ' + ], {}, (editor, _) => { + editor.setPosition(new Position(1, 1)); + + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' '.length + 1, '001'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* '.length + 1, '002'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just '.length + 1, '003'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some '.length + 1, '004'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more '.length + 1, '005'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text '.length + 1, '006'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a'.length + 1, '007'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= '.length + 1, '008'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 '.length + 1, '009'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '010'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '011'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '012'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 '.length + 1, '013'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + '.length + 1, '014'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 '.length + 1, '015'); + moveWordStartRight(editor); assert.equal(editor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */ '.length + 1, '016'); + }); + }); +}); diff --git a/src/vs/editor/test/common/controller/cursor.test.ts b/src/vs/editor/test/common/controller/cursor.test.ts index a20d5f350eb9dc64a9f6c13fcee8e3d0d8a23c59..8b4d46c8ee59dbd4e806299646cbc3163a1a2790 100644 --- a/src/vs/editor/test/common/controller/cursor.test.ts +++ b/src/vs/editor/test/common/controller/cursor.test.ts @@ -40,30 +40,10 @@ function moveLeft(cursor: Cursor, inSelectionMode: boolean = false) { cursorCommand(cursor, inSelectionMode ? H.CursorLeftSelect : H.CursorLeft); } -function moveWordLeft(cursor: Cursor, inSelectionMode: boolean = false) { - cursorCommand(cursor, inSelectionMode ? H.CursorWordLeftSelect : H.CursorWordLeft); -} -function moveWordStartLeft(cursor: Cursor, inSelectionMode: boolean = false) { - cursorCommand(cursor, inSelectionMode ? H.CursorWordStartLeftSelect : H.CursorWordStartLeft); -} -function moveWordEndLeft(cursor: Cursor, inSelectionMode: boolean = false) { - cursorCommand(cursor, inSelectionMode ? H.CursorWordEndLeftSelect : H.CursorWordEndLeft); -} - function moveRight(cursor: Cursor, inSelectionMode: boolean = false) { cursorCommand(cursor, inSelectionMode ? H.CursorRightSelect : H.CursorRight); } -function moveWordRight(cursor: Cursor, inSelectionMode: boolean = false) { - cursorCommand(cursor, inSelectionMode ? H.CursorWordRightSelect : H.CursorWordRight); -} -function moveWordEndRight(cursor: Cursor, inSelectionMode: boolean = false) { - cursorCommand(cursor, inSelectionMode ? H.CursorWordEndRightSelect : H.CursorWordEndRight); -} -function moveWordStartRight(cursor: Cursor, inSelectionMode: boolean = false) { - cursorCommand(cursor, inSelectionMode ? H.CursorWordStartRightSelect : H.CursorWordStartRight); -} - function moveDown(cursor: Cursor, linesCount: number, inSelectionMode: boolean = false) { if (linesCount === 1) { cursorCommand(cursor, inSelectionMode ? H.CursorDownSelect : H.CursorDown); @@ -248,44 +228,6 @@ suite('Editor Controller - Cursor', () => { assertCursor(thisCursor, new Selection(2, 1, 1, 21)); }); - // --------- move word left - - test('move word left', () => { - moveTo(thisCursor, 5, 2); - let expectedStops = [ - [5, 1], - [4, 1], - [3, 11], - [3, 5], - [3, 1], - [2, 12], - [2, 5], - [2, 2], - [2, 1], - [1, 15], - [1, 9], - [1, 6], - [1, 1], - [1, 1], - ]; - - let actualStops: number[][] = []; - for (let i = 0; i < expectedStops.length; i++) { - moveWordLeft(thisCursor); - let pos = thisCursor.getPosition(); - actualStops.push([pos.lineNumber, pos.column]); - } - - assert.deepEqual(actualStops, expectedStops); - }); - - test('move word left selection', () => { - moveTo(thisCursor, 5, 2); - assertCursor(thisCursor, new Position(5, 2)); - moveWordLeft(thisCursor, true); - assertCursor(thisCursor, new Selection(5, 2, 5, 1)); - }); - // --------- move right test('move right on bottom right position', () => { @@ -323,41 +265,6 @@ suite('Editor Controller - Cursor', () => { assertCursor(thisCursor, new Selection(1, 21, 2, 1)); }); - // --------- move word right - - test('move word right', () => { - moveTo(thisCursor, 1, 1); - let expectedStops = [ - [1, 8], - [1, 14], - [1, 19], - [1, 21], - [2, 4], - [2, 11], - [2, 16], - [3, 10], - [3, 17], - [4, 1], - [5, 2], - [5, 2], - ]; - - let actualStops: number[][] = []; - for (let i = 0; i < expectedStops.length; i++) { - moveWordRight(thisCursor); - let pos = thisCursor.getPosition(); - actualStops.push([pos.lineNumber, pos.column]); - } - - assert.deepEqual(actualStops, expectedStops); - }); - - test('move word right selection', () => { - moveTo(thisCursor, 1, 1); - assertCursor(thisCursor, new Position(1, 1)); - moveWordRight(thisCursor, true); - assertCursor(thisCursor, new Selection(1, 1, 1, 8)); - }); // --------- move down test('move down', () => { @@ -1962,168 +1869,6 @@ suite('Editor Controller - Regression tests', () => { }); }); - test('issue #832: moveWordLeft', () => { - usingCursor({ - text: [ - ' /* Just some more text a+= 3 +5-3 + 7 */ ' - ], - }, (model, cursor) => { - moveTo(cursor, 1, 50, false); - - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 '.length + 1, '001'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + '.length + 1, '002'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 '.length + 1, '003'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '004'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '005'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '006'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 '.length + 1, '007'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= '.length + 1, '008'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a'.length + 1, '009'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text '.length + 1, '010'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more '.length + 1, '011'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some '.length + 1, '012'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just '.length + 1, '013'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' /* '.length + 1, '014'); - moveWordLeft(cursor); assert.equal(cursor.getPosition().column, ' '.length + 1, '015'); - }); - }); - - test('moveWordStartLeft', () => { - usingCursor({ - text: [ - ' /* Just some more text a+= 3 +5-3 + 7 */ ' - ], - }, (model, cursor) => { - moveTo(cursor, 1, 50, false); - - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 '.length + 1, '001'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + '.length + 1, '002'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 '.length + 1, '003'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '004'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '005'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '006'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 '.length + 1, '007'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= '.length + 1, '008'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a'.length + 1, '009'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text '.length + 1, '010'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more '.length + 1, '011'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some '.length + 1, '012'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just '.length + 1, '013'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' /* '.length + 1, '014'); - moveWordStartLeft(cursor); assert.equal(cursor.getPosition().column, ' '.length + 1, '015'); - }); - }); - - test('moveWordEndLeft', () => { - usingCursor({ - text: [ - ' /* Just some more text a+= 3 +5-3 + 7 */ ' - ], - }, (model, cursor) => { - moveTo(cursor, 1, 50, false); - - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */'.length + 1, '001'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7'.length + 1, '002'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 +'.length + 1, '003'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3'.length + 1, '004'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '005'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '006'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '007'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3'.length + 1, '008'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+='.length + 1, '009'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a'.length + 1, '010'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text'.length + 1, '011'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more'.length + 1, '012'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just some'.length + 1, '013'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /* Just'.length + 1, '014'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ' /*'.length + 1, '015'); - moveWordEndLeft(cursor); assert.equal(cursor.getPosition().column, ''.length + 1, '016'); - }); - }); - - test('issue #832: moveWordRight', () => { - usingCursor({ - text: [ - ' /* Just some more text a+= 3 +5-3 + 7 */ ' - ], - }, (model, cursor) => { - moveTo(cursor, 1, 1, false); - - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /*'.length + 1, '001'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just'.length + 1, '003'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some'.length + 1, '004'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more'.length + 1, '005'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text'.length + 1, '006'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a'.length + 1, '007'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+='.length + 1, '008'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3'.length + 1, '009'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '010'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '011'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '012'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3'.length + 1, '013'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 +'.length + 1, '014'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7'.length + 1, '015'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */'.length + 1, '016'); - moveWordRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */ '.length + 1, '016'); - - }); - }); - - test('moveWordEndRight', () => { - usingCursor({ - text: [ - ' /* Just some more text a+= 3 +5-3 + 7 */ ' - ], - }, (model, cursor) => { - moveTo(cursor, 1, 1, false); - - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /*'.length + 1, '001'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just'.length + 1, '003'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some'.length + 1, '004'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more'.length + 1, '005'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text'.length + 1, '006'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a'.length + 1, '007'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+='.length + 1, '008'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3'.length + 1, '009'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '010'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '011'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '012'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3'.length + 1, '013'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 +'.length + 1, '014'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7'.length + 1, '015'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */'.length + 1, '016'); - moveWordEndRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */ '.length + 1, '016'); - - }); - }); - - test('moveWordStartRight', () => { - usingCursor({ - text: [ - ' /* Just some more text a+= 3 +5-3 + 7 */ ' - ], - }, (model, cursor) => { - moveTo(cursor, 1, 1, false); - - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' '.length + 1, '001'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* '.length + 1, '002'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just '.length + 1, '003'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some '.length + 1, '004'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more '.length + 1, '005'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text '.length + 1, '006'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a'.length + 1, '007'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= '.length + 1, '008'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 '.length + 1, '009'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +'.length + 1, '010'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5'.length + 1, '011'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-'.length + 1, '012'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 '.length + 1, '013'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + '.length + 1, '014'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 '.length + 1, '015'); - moveWordStartRight(cursor); assert.equal(cursor.getPosition().column, ' /* Just some more text a+= 3 +5-3 + 7 */ '.length + 1, '016'); - }); - }); - test('issue #832: word right', () => { usingCursor({ diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index be3a31eff5d57c9991dc810d414f0f5f90fae343..21027d127b36564d441918f121c34364c291c63d 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -3450,20 +3450,8 @@ declare module monaco.editor { ExecuteCommands: string; CursorLeft: string; CursorLeftSelect: string; - CursorWordLeft: string; - CursorWordStartLeft: string; - CursorWordEndLeft: string; - CursorWordLeftSelect: string; - CursorWordStartLeftSelect: string; - CursorWordEndLeftSelect: string; CursorRight: string; CursorRightSelect: string; - CursorWordRight: string; - CursorWordStartRight: string; - CursorWordEndRight: string; - CursorWordRightSelect: string; - CursorWordStartRightSelect: string; - CursorWordEndRightSelect: string; CursorUp: string; CursorUpSelect: string; CursorDown: string; diff --git a/src/vs/workbench/parts/debug/browser/debugEditorActions.ts b/src/vs/workbench/parts/debug/browser/debugEditorActions.ts index ca13908fcd8bf6b6412a8e3abdd0c56c1be4735e..21f8c85dbd798d74d18e87f1bc424c637c0844fd 100644 --- a/src/vs/workbench/parts/debug/browser/debugEditorActions.ts +++ b/src/vs/workbench/parts/debug/browser/debugEditorActions.ts @@ -268,7 +268,7 @@ class CloseBreakpointWidgetCommand extends EditorCommand { }); } - protected runEditorCommand(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void { + public runEditorCommand(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void { return editor.getContribution(EDITOR_CONTRIBUTION_ID).closeBreakpointWidget(); } }