Skip to content

Commit

Permalink
Implementation of editor.action.insertCursorAsEndOfEachSelectedLine -…
Browse files Browse the repository at this point in the history
… inspired by issue microsoft#950 and pull microsoft#961 - the same behaviour of Sublime Text ctrl+shift+l command...

Signed-off-by: Richard Natal <[email protected]>
  • Loading branch information
Bigous committed Dec 19, 2015
1 parent c173586 commit 47f69de
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/vs/editor/contrib/multicursor/common/multicursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import nls = require('vs/nls');
import {CommonEditorRegistry, ContextKey, EditorActionDescriptor} from 'vs/editor/common/editorCommonExtensions';
import {HandlerEditorAction} from 'vs/editor/common/editorAction';
import {TPromise} from 'vs/base/common/winjs.base';
import {EditorAction, HandlerEditorAction} from 'vs/editor/common/editorAction';
import EditorCommon = require('vs/editor/common/editorCommon');
import {INullService} from 'vs/platform/instantiation/common/instantiation';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';
Expand All @@ -27,6 +28,44 @@ class InsertCursorBelow extends HandlerEditorAction {
}
}

class InsertCursorsFromLineSelection extends EditorAction {
static ID = 'editor.action.insertCursorAtEndOfEachLineSelected';

constructor(descriptor:EditorCommon.IEditorActionDescriptorData, editor:EditorCommon.ICommonCodeEditor, @INullService ns) {
super(descriptor, editor);
}

public run(): TPromise<boolean> {
let sel = this.editor.getSelection();
if(!sel.isEmpty()) {
let model = this.editor.getModel();
let sels = new Array<EditorCommon.ISelection>();
let sStart = sel.getStartPosition();
let sEnd = sel.getEndPosition();
for (var i = sStart.lineNumber; i <= sEnd.lineNumber; i++) {
if(i !== sEnd.lineNumber) {
let lEnd = model.getLineMaxColumn(i);
sels.push({
selectionStartLineNumber: i,
selectionStartColumn: lEnd,
positionLineNumber: i,
positionColumn: lEnd
});
} else if( sEnd.column > 0 ) {
sels.push({
selectionStartLineNumber: sEnd.lineNumber,
selectionStartColumn: sEnd.column,
positionLineNumber: sEnd.lineNumber,
positionColumn: sEnd.column
});
}
}
this.editor.setSelections(sels);
}
return TPromise.as(true);
}
}


// register actions
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(InsertCursorAbove, InsertCursorAbove.ID, nls.localize('mutlicursor.insertAbove', "Add Cursor Above"), {
Expand All @@ -45,3 +84,7 @@ CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(InsertCurso
secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.DownArrow]
}
}));
CommonEditorRegistry.registerEditorAction(new EditorActionDescriptor(InsertCursorsFromLineSelection, InsertCursorsFromLineSelection.ID, nls.localize('mutlicursor.insertAtEndOfEachLineSelected', "Create multiple cursors from selected lines"), {
context: ContextKey.EditorTextFocus,
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_I
}));

0 comments on commit 47f69de

Please sign in to comment.