From cabcd28c2c6a5085c55a8fb29e1901af3566f9c9 Mon Sep 17 00:00:00 2001 From: Matt Downs Date: Wed, 21 Dec 2016 15:10:27 -0500 Subject: [PATCH] Fix for #16771. Now insertCursorAtEndOfEachLineSelected works with multiple selections. --- .../contrib/multicursor/common/multicursor.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/vs/editor/contrib/multicursor/common/multicursor.ts b/src/vs/editor/contrib/multicursor/common/multicursor.ts index 387f6dddd33a0..d336789465259 100644 --- a/src/vs/editor/contrib/multicursor/common/multicursor.ts +++ b/src/vs/editor/contrib/multicursor/common/multicursor.ts @@ -8,6 +8,7 @@ import * as nls from 'vs/nls'; import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { Handler, ICommonCodeEditor, EditorContextKeys, ISelection } from 'vs/editor/common/editorCommon'; import { editorAction, ServicesAccessor, EditorAction, HandlerEditorAction } from 'vs/editor/common/editorCommonExtensions'; +import { Selection } from 'vs/editor/common/core/selection'; @editorAction class InsertCursorAbove extends HandlerEditorAction { @@ -67,10 +68,9 @@ class InsertCursorAtEndOfEachLineSelected extends EditorAction { }); } - public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void { - let selection = editor.getSelection(); + private getCursorsForSelection(selection: Selection, editor: ICommonCodeEditor): Array { if (selection.isEmpty()) { - return; + return []; } let model = editor.getModel(); @@ -95,6 +95,16 @@ class InsertCursorAtEndOfEachLineSelected extends EditorAction { }); } } - editor.setSelections(newSelections); + return newSelections; + } + + public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void { + let selections = editor.getSelections(); + let newSelections = selections.map((selection) => this.getCursorsForSelection(selection, editor)) + .reduce((prev, curr) => { return prev.concat(curr); }); + + if (newSelections.length > 0) { + editor.setSelections(newSelections); + } } }