Merge commit 'be3e8236086165e5e45a5a10783823874b3f3ebd' as 'lib/vscode'

This commit is contained in:
Joe Previte
2020-12-15 15:52:33 -07:00
4649 changed files with 1311795 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorAction, IActionOptions, ServicesAccessor, registerEditorAction } from 'vs/editor/browser/editorExtensions';
import { ICommand } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { MoveCaretCommand } from 'vs/editor/contrib/caretOperations/moveCaretCommand';
class MoveCaretAction extends EditorAction {
private readonly left: boolean;
constructor(left: boolean, opts: IActionOptions) {
super(opts);
this.left = left;
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
if (!editor.hasModel()) {
return;
}
let commands: ICommand[] = [];
let selections = editor.getSelections();
for (const selection of selections) {
commands.push(new MoveCaretCommand(selection, this.left));
}
editor.pushUndoStop();
editor.executeCommands(this.id, commands);
editor.pushUndoStop();
}
}
class MoveCaretLeftAction extends MoveCaretAction {
constructor() {
super(true, {
id: 'editor.action.moveCarretLeftAction',
label: nls.localize('caret.moveLeft', "Move Selected Text Left"),
alias: 'Move Selected Text Left',
precondition: EditorContextKeys.writable
});
}
}
class MoveCaretRightAction extends MoveCaretAction {
constructor() {
super(false, {
id: 'editor.action.moveCarretRightAction',
label: nls.localize('caret.moveRight', "Move Selected Text Right"),
alias: 'Move Selected Text Right',
precondition: EditorContextKeys.writable
});
}
}
registerEditorAction(MoveCaretLeftAction);
registerEditorAction(MoveCaretRightAction);

View File

@@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { ICommand, ICursorStateComputerData, IEditOperationBuilder } from 'vs/editor/common/editorCommon';
import { ITextModel } from 'vs/editor/common/model';
export class MoveCaretCommand implements ICommand {
private readonly _selection: Selection;
private readonly _isMovingLeft: boolean;
constructor(selection: Selection, isMovingLeft: boolean) {
this._selection = selection;
this._isMovingLeft = isMovingLeft;
}
public getEditOperations(model: ITextModel, builder: IEditOperationBuilder): void {
if (this._selection.startLineNumber !== this._selection.endLineNumber || this._selection.isEmpty()) {
return;
}
const lineNumber = this._selection.startLineNumber;
const startColumn = this._selection.startColumn;
const endColumn = this._selection.endColumn;
if (this._isMovingLeft && startColumn === 1) {
return;
}
if (!this._isMovingLeft && endColumn === model.getLineMaxColumn(lineNumber)) {
return;
}
if (this._isMovingLeft) {
const rangeBefore = new Range(lineNumber, startColumn - 1, lineNumber, startColumn);
const charBefore = model.getValueInRange(rangeBefore);
builder.addEditOperation(rangeBefore, null);
builder.addEditOperation(new Range(lineNumber, endColumn, lineNumber, endColumn), charBefore);
} else {
const rangeAfter = new Range(lineNumber, endColumn, lineNumber, endColumn + 1);
const charAfter = model.getValueInRange(rangeAfter);
builder.addEditOperation(rangeAfter, null);
builder.addEditOperation(new Range(lineNumber, startColumn, lineNumber, startColumn), charAfter);
}
}
public computeCursorState(model: ITextModel, helper: ICursorStateComputerData): Selection {
if (this._isMovingLeft) {
return new Selection(this._selection.startLineNumber, this._selection.startColumn - 1, this._selection.endLineNumber, this._selection.endColumn - 1);
} else {
return new Selection(this._selection.startLineNumber, this._selection.startColumn + 1, this._selection.endLineNumber, this._selection.endColumn + 1);
}
}
}

View File

@@ -0,0 +1,69 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Selection } from 'vs/editor/common/core/selection';
import { MoveCaretCommand } from 'vs/editor/contrib/caretOperations/moveCaretCommand';
import { testCommand } from 'vs/editor/test/browser/testCommand';
function testMoveCaretLeftCommand(lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection): void {
testCommand(lines, null, selection, (sel) => new MoveCaretCommand(sel, true), expectedLines, expectedSelection);
}
function testMoveCaretRightCommand(lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection): void {
testCommand(lines, null, selection, (sel) => new MoveCaretCommand(sel, false), expectedLines, expectedSelection);
}
suite('Editor Contrib - Move Caret Command', () => {
test('move selection to left', function () {
testMoveCaretLeftCommand(
[
'012345'
],
new Selection(1, 3, 1, 5),
[
'023145'
],
new Selection(1, 2, 1, 4)
);
});
test('move selection to right', function () {
testMoveCaretRightCommand(
[
'012345'
],
new Selection(1, 3, 1, 5),
[
'014235'
],
new Selection(1, 4, 1, 6)
);
});
test('move selection to left - from first column - no change', function () {
testMoveCaretLeftCommand(
[
'012345'
],
new Selection(1, 1, 1, 1),
[
'012345'
],
new Selection(1, 1, 1, 1)
);
});
test('move selection to right - from last column - no change', function () {
testMoveCaretRightCommand(
[
'012345'
],
new Selection(1, 5, 1, 7),
[
'012345'
],
new Selection(1, 5, 1, 7)
);
});
});

View File

@@ -0,0 +1,84 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorAction, ServicesAccessor, registerEditorAction } from 'vs/editor/browser/editorExtensions';
import { ReplaceCommand } from 'vs/editor/common/commands/replaceCommand';
import { Range } from 'vs/editor/common/core/range';
import { ICommand } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { MoveOperations } from 'vs/editor/common/controller/cursorMoveOperations';
class TransposeLettersAction extends EditorAction {
constructor() {
super({
id: 'editor.action.transposeLetters',
label: nls.localize('transposeLetters.label', "Transpose Letters"),
alias: 'Transpose Letters',
precondition: EditorContextKeys.writable,
kbOpts: {
kbExpr: EditorContextKeys.textInputFocus,
primary: 0,
mac: {
primary: KeyMod.WinCtrl | KeyCode.KEY_T
},
weight: KeybindingWeight.EditorContrib
}
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
if (!editor.hasModel()) {
return;
}
let model = editor.getModel();
let commands: ICommand[] = [];
let selections = editor.getSelections();
for (let selection of selections) {
if (!selection.isEmpty()) {
continue;
}
let lineNumber = selection.startLineNumber;
let column = selection.startColumn;
let lastColumn = model.getLineMaxColumn(lineNumber);
if (lineNumber === 1 && (column === 1 || (column === 2 && lastColumn === 2))) {
// at beginning of file, nothing to do
continue;
}
// handle special case: when at end of line, transpose left two chars
// otherwise, transpose left and right chars
let endPosition = (column === lastColumn) ?
selection.getPosition() :
MoveOperations.rightPosition(model, selection.getPosition().lineNumber, selection.getPosition().column);
let middlePosition = MoveOperations.leftPosition(model, endPosition.lineNumber, endPosition.column);
let beginPosition = MoveOperations.leftPosition(model, middlePosition.lineNumber, middlePosition.column);
let leftChar = model.getValueInRange(Range.fromPositions(beginPosition, middlePosition));
let rightChar = model.getValueInRange(Range.fromPositions(middlePosition, endPosition));
let replaceRange = Range.fromPositions(beginPosition, endPosition);
commands.push(new ReplaceCommand(replaceRange, rightChar + leftChar));
}
if (commands.length > 0) {
editor.pushUndoStop();
editor.executeCommands(this.id, commands);
editor.pushUndoStop();
}
}
}
registerEditorAction(TransposeLettersAction);