Merge from vscode c58aaab8a1cc22a7139b761166a0d4f37d41e998 (#7880)

* Merge from vscode c58aaab8a1cc22a7139b761166a0d4f37d41e998

* fix pipelines

* fix strict-null-checks

* add missing files
This commit is contained in:
Anthony Dresser
2019-10-21 22:12:22 -07:00
committed by GitHub
parent 7c9be74970
commit 1e22f47304
913 changed files with 18898 additions and 16536 deletions

View File

@@ -8,7 +8,7 @@ import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
import { ICodeEditor, IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorAction, IActionOptions, ServicesAccessor, registerEditorAction } from 'vs/editor/browser/editorExtensions';
import { ReplaceCommand, ReplaceCommandThatPreservesSelection } from 'vs/editor/common/commands/replaceCommand';
import { ReplaceCommand, ReplaceCommandThatPreservesSelection, ReplaceCommandThatSelectsText } from 'vs/editor/common/commands/replaceCommand';
import { TrimTrailingWhitespaceCommand } from 'vs/editor/common/commands/trimTrailingWhitespaceCommand';
import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations';
import { EditOperation } from 'vs/editor/common/core/editOperation';
@@ -97,6 +97,47 @@ class CopyLinesDownAction extends AbstractCopyLinesAction {
}
}
export class DuplicateSelectionAction extends EditorAction {
constructor() {
super({
id: 'editor.action.duplicateSelection',
label: nls.localize('duplicateSelection', "Duplicate Selection"),
alias: 'Duplicate Selection',
precondition: EditorContextKeys.writable,
menubarOpts: {
menuId: MenuId.MenubarSelectionMenu,
group: '2_line',
title: nls.localize({ key: 'miDuplicateSelection', comment: ['&& denotes a mnemonic'] }, "&&Duplicate Selection"),
order: 5
}
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
if (!editor.hasModel()) {
return;
}
const commands: ICommand[] = [];
const selections = editor.getSelections();
const model = editor.getModel();
for (const selection of selections) {
if (selection.isEmpty()) {
commands.push(new CopyLinesCommand(selection, true));
} else {
const insertSelection = new Selection(selection.endLineNumber, selection.endColumn, selection.endLineNumber, selection.endColumn);
commands.push(new ReplaceCommandThatSelectsText(insertSelection, model.getValueInRange(selection)));
}
}
editor.pushUndoStop();
editor.executeCommands(this.id, commands);
editor.pushUndoStop();
}
}
// move lines
abstract class AbstractMoveLinesAction extends EditorAction {
@@ -989,6 +1030,7 @@ export class TitleCaseAction extends AbstractCaseAction {
registerEditorAction(CopyLinesUpAction);
registerEditorAction(CopyLinesDownAction);
registerEditorAction(DuplicateSelectionAction);
registerEditorAction(MoveLinesUpAction);
registerEditorAction(MoveLinesDownAction);
registerEditorAction(SortLinesAscendingAction);

View File

@@ -3,9 +3,12 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { Selection } from 'vs/editor/common/core/selection';
import { CopyLinesCommand } from 'vs/editor/contrib/linesOperations/copyLinesCommand';
import { testCommand } from 'vs/editor/test/browser/testCommand';
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
import { DuplicateSelectionAction } from 'vs/editor/contrib/linesOperations/linesOperations';
function testCopyLinesDownCommand(lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection): void {
testCommand(lines, null, selection, (sel) => new CopyLinesCommand(sel, true), expectedLines, expectedSelection);
@@ -195,3 +198,61 @@ suite('Editor Contrib - Copy Lines Command', () => {
);
});
});
suite('Editor Contrib - Duplicate Selection', () => {
const duplicateSelectionAction = new DuplicateSelectionAction();
function testDuplicateSelectionAction(lines: string[], selections: Selection[], expectedLines: string[], expectedSelections: Selection[]): void {
withTestCodeEditor(lines.join('\n'), {}, (editor, cursor) => {
editor.setSelections(selections);
duplicateSelectionAction.run(null!, editor, {});
assert.deepEqual(editor.getValue(), expectedLines.join('\n'));
assert.deepEqual(editor.getSelections()!.map(s => s.toString()), expectedSelections.map(s => s.toString()));
});
}
test('empty selection', function () {
testDuplicateSelectionAction(
[
'first',
'second line',
'third line',
'fourth line',
'fifth'
],
[new Selection(2, 2, 2, 2), new Selection(3, 2, 3, 2)],
[
'first',
'second line',
'second line',
'third line',
'third line',
'fourth line',
'fifth'
],
[new Selection(3, 2, 3, 2), new Selection(5, 2, 5, 2)]
);
});
test('with selection', function () {
testDuplicateSelectionAction(
[
'first',
'second line',
'third line',
'fourth line',
'fifth'
],
[new Selection(2, 1, 2, 4), new Selection(3, 1, 3, 4)],
[
'first',
'secsecond line',
'thithird line',
'fourth line',
'fifth'
],
[new Selection(2, 4, 2, 7), new Selection(3, 4, 3, 7)]
);
});
});