mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from master
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection, SelectionDirection } from 'vs/editor/common/core/selection';
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
|
||||
@@ -2,29 +2,28 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as nls from 'vs/nls';
|
||||
import { KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
|
||||
import { SortLinesCommand } from 'vs/editor/contrib/linesOperations/sortLinesCommand';
|
||||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import { TrimTrailingWhitespaceCommand } from 'vs/editor/common/commands/trimTrailingWhitespaceCommand';
|
||||
import { ICommand } from 'vs/editor/common/editorCommon';
|
||||
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
import { ReplaceCommand, ReplaceCommandThatPreservesSelection } from 'vs/editor/common/commands/replaceCommand';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { registerEditorAction, ServicesAccessor, IActionOptions, EditorAction } from 'vs/editor/browser/editorExtensions';
|
||||
import { CopyLinesCommand } from './copyLinesCommand';
|
||||
import { DeleteLinesCommand } from './deleteLinesCommand';
|
||||
import { MoveLinesCommand } from './moveLinesCommand';
|
||||
import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations';
|
||||
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { EditorAction, IActionOptions, ServicesAccessor, registerEditorAction } from 'vs/editor/browser/editorExtensions';
|
||||
import { ReplaceCommand, ReplaceCommandThatPreservesSelection } 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';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { ICommand } from 'vs/editor/common/editorCommon';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
|
||||
import { CopyLinesCommand } from 'vs/editor/contrib/linesOperations/copyLinesCommand';
|
||||
import { DeleteLinesCommand } from 'vs/editor/contrib/linesOperations/deleteLinesCommand';
|
||||
import { MoveLinesCommand } from 'vs/editor/contrib/linesOperations/moveLinesCommand';
|
||||
import { SortLinesCommand } from 'vs/editor/contrib/linesOperations/sortLinesCommand';
|
||||
import { MenuId } from 'vs/platform/actions/common/actions';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
|
||||
// copy lines
|
||||
|
||||
@@ -40,7 +39,7 @@ abstract class AbstractCopyLinesAction extends EditorAction {
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
|
||||
let commands: ICommand[] = [];
|
||||
let selections = editor.getSelections();
|
||||
let selections = editor.getSelections() || [];
|
||||
|
||||
for (let i = 0; i < selections.length; i++) {
|
||||
commands.push(new CopyLinesCommand(selections[i], this.down));
|
||||
@@ -112,7 +111,7 @@ abstract class AbstractMoveLinesAction extends EditorAction {
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
|
||||
let commands: ICommand[] = [];
|
||||
let selections = editor.getSelections();
|
||||
let selections = editor.getSelections() || [];
|
||||
let autoIndent = editor.getConfiguration().autoIndent;
|
||||
|
||||
for (let i = 0; i < selections.length; i++) {
|
||||
@@ -180,7 +179,7 @@ export abstract class AbstractSortLinesAction extends EditorAction {
|
||||
}
|
||||
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
const selections = editor.getSelections();
|
||||
const selections = editor.getSelections() || [];
|
||||
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
const selection = selections[i];
|
||||
@@ -247,10 +246,15 @@ export class TrimTrailingWhitespaceAction extends EditorAction {
|
||||
// See https://github.com/editorconfig/editorconfig-vscode/issues/47
|
||||
// It is very convenient for the editor config extension to invoke this action.
|
||||
// So, if we get a reason:'auto-save' passed in, let's preserve cursor positions.
|
||||
cursors = editor.getSelections().map(s => new Position(s.positionLineNumber, s.positionColumn));
|
||||
cursors = (editor.getSelections() || []).map(s => new Position(s.positionLineNumber, s.positionColumn));
|
||||
}
|
||||
|
||||
let command = new TrimTrailingWhitespaceCommand(editor.getSelection(), cursors);
|
||||
let selection = editor.getSelection();
|
||||
if (selection === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let command = new TrimTrailingWhitespaceCommand(selection, cursors);
|
||||
|
||||
editor.pushUndoStop();
|
||||
editor.executeCommands(this.id, [command]);
|
||||
@@ -266,7 +270,7 @@ interface IDeleteLinesOperation {
|
||||
positionColumn: number;
|
||||
}
|
||||
|
||||
class DeleteLinesAction extends EditorAction {
|
||||
export class DeleteLinesAction extends EditorAction {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
@@ -298,7 +302,11 @@ class DeleteLinesAction extends EditorAction {
|
||||
|
||||
private _getLinesToRemove(editor: ICodeEditor): IDeleteLinesOperation[] {
|
||||
// Construct delete operations
|
||||
let operations: IDeleteLinesOperation[] = editor.getSelections().map((s) => {
|
||||
let selections = editor.getSelections();
|
||||
if (selections === null) {
|
||||
return [];
|
||||
}
|
||||
let operations: IDeleteLinesOperation[] = selections.map((s) => {
|
||||
|
||||
let endLineNumber = s.endLineNumber;
|
||||
if (s.startLineNumber < s.endLineNumber && s.endColumn === 1) {
|
||||
@@ -314,14 +322,17 @@ class DeleteLinesAction extends EditorAction {
|
||||
|
||||
// Sort delete operations
|
||||
operations.sort((a, b) => {
|
||||
if (a.startLineNumber === b.startLineNumber) {
|
||||
return a.endLineNumber - b.endLineNumber;
|
||||
}
|
||||
return a.startLineNumber - b.startLineNumber;
|
||||
});
|
||||
|
||||
// Merge delete operations on consecutive lines
|
||||
// Merge delete operations which are adjacent or overlapping
|
||||
let mergedOperations: IDeleteLinesOperation[] = [];
|
||||
let previousOperation = operations[0];
|
||||
for (let i = 1; i < operations.length; i++) {
|
||||
if (previousOperation.endLineNumber + 1 === operations[i].startLineNumber) {
|
||||
if (previousOperation.endLineNumber + 1 >= operations[i].startLineNumber) {
|
||||
// Merge current operations into the previous one
|
||||
previousOperation.endLineNumber = operations[i].endLineNumber;
|
||||
} else {
|
||||
@@ -353,8 +364,12 @@ export class IndentLinesAction extends EditorAction {
|
||||
}
|
||||
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
const cursors = editor._getCursors();
|
||||
if (!cursors) {
|
||||
return;
|
||||
}
|
||||
editor.pushUndoStop();
|
||||
editor.executeCommands(this.id, TypeOperations.indent(editor._getCursorConfiguration(), editor.getModel(), editor.getSelections()));
|
||||
editor.executeCommands(this.id, TypeOperations.indent(cursors.context.config, editor.getModel(), editor.getSelections()));
|
||||
editor.pushUndoStop();
|
||||
}
|
||||
}
|
||||
@@ -375,7 +390,7 @@ class OutdentLinesAction extends EditorAction {
|
||||
}
|
||||
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
CoreEditingCommands.Outdent.runEditorCommand(null, editor, null);
|
||||
CoreEditingCommands.Outdent.runEditorCommand(_accessor, editor, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,8 +410,12 @@ export class InsertLineBeforeAction extends EditorAction {
|
||||
}
|
||||
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
const cursors = editor._getCursors();
|
||||
if (!cursors) {
|
||||
return;
|
||||
}
|
||||
editor.pushUndoStop();
|
||||
editor.executeCommands(this.id, TypeOperations.lineInsertBefore(editor._getCursorConfiguration(), editor.getModel(), editor.getSelections()));
|
||||
editor.executeCommands(this.id, TypeOperations.lineInsertBefore(cursors.context.config, editor.getModel(), editor.getSelections()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,14 +435,22 @@ export class InsertLineAfterAction extends EditorAction {
|
||||
}
|
||||
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
const cursors = editor._getCursors();
|
||||
if (!cursors) {
|
||||
return;
|
||||
}
|
||||
editor.pushUndoStop();
|
||||
editor.executeCommands(this.id, TypeOperations.lineInsertAfter(editor._getCursorConfiguration(), editor.getModel(), editor.getSelections()));
|
||||
editor.executeCommands(this.id, TypeOperations.lineInsertAfter(cursors.context.config, editor.getModel(), editor.getSelections()));
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class AbstractDeleteAllToBoundaryAction extends EditorAction {
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
const primaryCursor = editor.getSelection();
|
||||
if (primaryCursor === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let rangesToDelete = this._getRangesToDelete(editor);
|
||||
// merge overlapping selections
|
||||
let effectiveRanges: Range[] = [];
|
||||
@@ -469,7 +496,7 @@ export class DeleteAllLeftAction extends AbstractDeleteAllToBoundaryAction {
|
||||
precondition: EditorContextKeys.writable,
|
||||
kbOpts: {
|
||||
kbExpr: EditorContextKeys.textInputFocus,
|
||||
primary: null,
|
||||
primary: 0,
|
||||
mac: { primary: KeyMod.CtrlCmd | KeyCode.Backspace },
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
@@ -477,7 +504,7 @@ export class DeleteAllLeftAction extends AbstractDeleteAllToBoundaryAction {
|
||||
}
|
||||
|
||||
_getEndCursorState(primaryCursor: Range, rangesToDelete: Range[]): Selection[] {
|
||||
let endPrimaryCursor: Selection;
|
||||
let endPrimaryCursor: Selection | null = null;
|
||||
let endCursorState: Selection[] = [];
|
||||
let deletedLines = 0;
|
||||
|
||||
@@ -507,15 +534,24 @@ export class DeleteAllLeftAction extends AbstractDeleteAllToBoundaryAction {
|
||||
}
|
||||
|
||||
_getRangesToDelete(editor: ICodeEditor): Range[] {
|
||||
let rangesToDelete: Range[] = editor.getSelections();
|
||||
let selections = editor.getSelections();
|
||||
if (selections === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let rangesToDelete: Range[] = selections;
|
||||
let model = editor.getModel();
|
||||
|
||||
if (model === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
rangesToDelete.sort(Range.compareRangesUsingStarts);
|
||||
rangesToDelete = rangesToDelete.map(selection => {
|
||||
if (selection.isEmpty()) {
|
||||
if (selection.startColumn === 1) {
|
||||
let deleteFromLine = Math.max(1, selection.startLineNumber - 1);
|
||||
let deleteFromColumn = selection.startLineNumber === 1 ? 1 : model.getLineContent(deleteFromLine).length + 1;
|
||||
let deleteFromColumn = selection.startLineNumber === 1 ? 1 : model!.getLineContent(deleteFromLine).length + 1;
|
||||
return new Range(deleteFromLine, deleteFromColumn, selection.startLineNumber, 1);
|
||||
} else {
|
||||
return new Range(selection.startLineNumber, 1, selection.startLineNumber, selection.startColumn);
|
||||
@@ -538,7 +574,7 @@ export class DeleteAllRightAction extends AbstractDeleteAllToBoundaryAction {
|
||||
precondition: EditorContextKeys.writable,
|
||||
kbOpts: {
|
||||
kbExpr: EditorContextKeys.textInputFocus,
|
||||
primary: null,
|
||||
primary: 0,
|
||||
mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_K, secondary: [KeyMod.CtrlCmd | KeyCode.Delete] },
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
@@ -546,7 +582,7 @@ export class DeleteAllRightAction extends AbstractDeleteAllToBoundaryAction {
|
||||
}
|
||||
|
||||
_getEndCursorState(primaryCursor: Range, rangesToDelete: Range[]): Selection[] {
|
||||
let endPrimaryCursor: Selection;
|
||||
let endPrimaryCursor: Selection | null = null;
|
||||
let endCursorState: Selection[] = [];
|
||||
for (let i = 0, len = rangesToDelete.length, offset = 0; i < len; i++) {
|
||||
let range = rangesToDelete[i];
|
||||
@@ -568,10 +604,19 @@ export class DeleteAllRightAction extends AbstractDeleteAllToBoundaryAction {
|
||||
|
||||
_getRangesToDelete(editor: ICodeEditor): Range[] {
|
||||
let model = editor.getModel();
|
||||
if (model === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let rangesToDelete: Range[] = editor.getSelections().map((sel) => {
|
||||
let selections = editor.getSelections();
|
||||
|
||||
if (selections === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let rangesToDelete: Range[] = selections.map((sel) => {
|
||||
if (sel.isEmpty()) {
|
||||
const maxColumn = model.getLineMaxColumn(sel.startLineNumber);
|
||||
const maxColumn = model!.getLineMaxColumn(sel.startLineNumber);
|
||||
|
||||
if (sel.startColumn === maxColumn) {
|
||||
return new Range(sel.startLineNumber, sel.startColumn, sel.startLineNumber + 1, 1);
|
||||
@@ -605,7 +650,14 @@ export class JoinLinesAction extends EditorAction {
|
||||
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
let selections = editor.getSelections();
|
||||
if (selections === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let primaryCursor = editor.getSelection();
|
||||
if (primaryCursor === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
selections.sort(Range.compareRangesUsingStarts);
|
||||
let reducedSelections: Selection[] = [];
|
||||
@@ -613,7 +665,7 @@ export class JoinLinesAction extends EditorAction {
|
||||
let lastSelection = selections.reduce((previousValue, currentValue) => {
|
||||
if (previousValue.isEmpty()) {
|
||||
if (previousValue.endLineNumber === currentValue.startLineNumber) {
|
||||
if (primaryCursor.equalsSelection(previousValue)) {
|
||||
if (primaryCursor!.equalsSelection(previousValue)) {
|
||||
primaryCursor = currentValue;
|
||||
}
|
||||
return currentValue;
|
||||
@@ -638,8 +690,12 @@ export class JoinLinesAction extends EditorAction {
|
||||
reducedSelections.push(lastSelection);
|
||||
|
||||
let model = editor.getModel();
|
||||
let edits = [];
|
||||
let endCursorState = [];
|
||||
if (model === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let edits: IIdentifiedSingleEditOperation[] = [];
|
||||
let endCursorState: Selection[] = [];
|
||||
let endPrimaryCursor = primaryCursor;
|
||||
let lineOffset = 0;
|
||||
|
||||
@@ -748,7 +804,15 @@ export class TransposeAction extends EditorAction {
|
||||
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
let selections = editor.getSelections();
|
||||
if (selections === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let model = editor.getModel();
|
||||
if (model === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let commands: ICommand[] = [];
|
||||
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
@@ -789,7 +853,15 @@ export class TransposeAction extends EditorAction {
|
||||
export abstract class AbstractCaseAction extends EditorAction {
|
||||
public run(_accessor: ServicesAccessor, editor: ICodeEditor): void {
|
||||
let selections = editor.getSelections();
|
||||
if (selections === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let model = editor.getModel();
|
||||
if (model === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let commands: ICommand[] = [];
|
||||
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
|
||||
@@ -2,18 +2,17 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { ShiftCommand } from 'vs/editor/common/commands/shiftCommand';
|
||||
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';
|
||||
import { LanguageConfigurationRegistry, IIndentConverter } from 'vs/editor/common/modes/languageConfigurationRegistry';
|
||||
import { ShiftCommand } from 'vs/editor/common/commands/shiftCommand';
|
||||
import * as IndentUtil from 'vs/editor/contrib/indentation/indentUtils';
|
||||
import { IndentAction } from 'vs/editor/common/modes/languageConfiguration';
|
||||
import { IIndentConverter, LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
|
||||
import { IndentConsts } from 'vs/editor/common/modes/supports/indentRules';
|
||||
import * as indentUtils from 'vs/editor/contrib/indentation/indentUtils';
|
||||
|
||||
export class MoveLinesCommand implements ICommand {
|
||||
|
||||
@@ -64,7 +63,7 @@ export class MoveLinesCommand implements ICommand {
|
||||
getLanguageIdAtPosition: (lineNumber: number, column: number) => {
|
||||
return model.getLanguageIdAtPosition(lineNumber, column);
|
||||
},
|
||||
getLineContent: <(lineNumber: number) => string>null,
|
||||
getLineContent: null as unknown as (lineNumber: number) => string,
|
||||
};
|
||||
|
||||
if (s.startLineNumber === s.endLineNumber && model.getLineMaxColumn(s.startLineNumber) === 1) {
|
||||
@@ -104,8 +103,8 @@ export class MoveLinesCommand implements ICommand {
|
||||
// if s.startLineNumber - 1 matches onEnter rule, we still honor that.
|
||||
if (movingLineMatchResult !== null) {
|
||||
let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(movingLineNumber));
|
||||
let newSpaceCnt = movingLineMatchResult + IndentUtil.getSpaceCnt(oldIndentation, tabSize);
|
||||
let newIndentation = IndentUtil.generateIndent(newSpaceCnt, tabSize, insertSpaces);
|
||||
let newSpaceCnt = movingLineMatchResult + indentUtils.getSpaceCnt(oldIndentation, tabSize);
|
||||
let newIndentation = indentUtils.generateIndent(newSpaceCnt, tabSize, insertSpaces);
|
||||
insertingText = newIndentation + this.trimLeft(movingLineText);
|
||||
} else {
|
||||
// no enter rule matches, let's check indentatin rules then.
|
||||
@@ -120,10 +119,10 @@ export class MoveLinesCommand implements ICommand {
|
||||
movingLineNumber, 1), s.startLineNumber, indentConverter);
|
||||
if (indentOfMovingLine !== null) {
|
||||
let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(movingLineNumber));
|
||||
let newSpaceCnt = IndentUtil.getSpaceCnt(indentOfMovingLine, tabSize);
|
||||
let oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndentation, tabSize);
|
||||
let newSpaceCnt = indentUtils.getSpaceCnt(indentOfMovingLine, tabSize);
|
||||
let oldSpaceCnt = indentUtils.getSpaceCnt(oldIndentation, tabSize);
|
||||
if (newSpaceCnt !== oldSpaceCnt) {
|
||||
let newIndentation = IndentUtil.generateIndent(newSpaceCnt, tabSize, insertSpaces);
|
||||
let newIndentation = indentUtils.generateIndent(newSpaceCnt, tabSize, insertSpaces);
|
||||
insertingText = newIndentation + this.trimLeft(movingLineText);
|
||||
}
|
||||
}
|
||||
@@ -156,8 +155,8 @@ export class MoveLinesCommand implements ICommand {
|
||||
|
||||
if (newIndentatOfMovingBlock !== null) {
|
||||
const oldIndentation = strings.getLeadingWhitespace(model.getLineContent(s.startLineNumber));
|
||||
const newSpaceCnt = IndentUtil.getSpaceCnt(newIndentatOfMovingBlock, tabSize);
|
||||
const oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndentation, tabSize);
|
||||
const newSpaceCnt = indentUtils.getSpaceCnt(newIndentatOfMovingBlock, tabSize);
|
||||
const oldSpaceCnt = indentUtils.getSpaceCnt(oldIndentation, tabSize);
|
||||
if (newSpaceCnt !== oldSpaceCnt) {
|
||||
const spaceCntOffset = newSpaceCnt - oldSpaceCnt;
|
||||
|
||||
@@ -200,8 +199,8 @@ export class MoveLinesCommand implements ICommand {
|
||||
if (indentOfFirstLine !== null) {
|
||||
// adjust the indentation of the moving block
|
||||
let oldIndent = strings.getLeadingWhitespace(model.getLineContent(s.startLineNumber));
|
||||
let newSpaceCnt = IndentUtil.getSpaceCnt(indentOfFirstLine, tabSize);
|
||||
let oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndent, tabSize);
|
||||
let newSpaceCnt = indentUtils.getSpaceCnt(indentOfFirstLine, tabSize);
|
||||
let oldSpaceCnt = indentUtils.getSpaceCnt(oldIndent, tabSize);
|
||||
if (newSpaceCnt !== oldSpaceCnt) {
|
||||
let spaceCntOffset = newSpaceCnt - oldSpaceCnt;
|
||||
|
||||
@@ -282,11 +281,11 @@ export class MoveLinesCommand implements ICommand {
|
||||
let oldIndentation = strings.getLeadingWhitespace(model.getLineContent(line));
|
||||
let newIndentation = strings.getLeadingWhitespace(enterPrefix);
|
||||
let indentMetadataOfMovelingLine = LanguageConfigurationRegistry.getIndentMetadata(model, line);
|
||||
if (indentMetadataOfMovelingLine & IndentConsts.DECREASE_MASK) {
|
||||
if (indentMetadataOfMovelingLine !== null && indentMetadataOfMovelingLine & IndentConsts.DECREASE_MASK) {
|
||||
newIndentation = indentConverter.unshiftIndent(newIndentation);
|
||||
}
|
||||
let newSpaceCnt = IndentUtil.getSpaceCnt(newIndentation, tabSize);
|
||||
let oldSpaceCnt = IndentUtil.getSpaceCnt(oldIndentation, tabSize);
|
||||
let newSpaceCnt = indentUtils.getSpaceCnt(newIndentation, tabSize);
|
||||
let oldSpaceCnt = indentUtils.getSpaceCnt(oldIndentation, tabSize);
|
||||
return newSpaceCnt - oldSpaceCnt;
|
||||
}
|
||||
}
|
||||
@@ -324,9 +323,9 @@ export class MoveLinesCommand implements ICommand {
|
||||
for (let i = s.startLineNumber; i <= s.endLineNumber; i++) {
|
||||
let lineContent = model.getLineContent(i);
|
||||
let originalIndent = strings.getLeadingWhitespace(lineContent);
|
||||
let originalSpacesCnt = IndentUtil.getSpaceCnt(originalIndent, tabSize);
|
||||
let originalSpacesCnt = indentUtils.getSpaceCnt(originalIndent, tabSize);
|
||||
let newSpacesCnt = originalSpacesCnt + offset;
|
||||
let newIndent = IndentUtil.generateIndent(newSpacesCnt, tabSize, insertSpaces);
|
||||
let newIndent = indentUtils.generateIndent(newSpacesCnt, tabSize, insertSpaces);
|
||||
|
||||
if (newIndent !== originalIndent) {
|
||||
builder.addEditOperation(new Range(i, 1, i, originalIndent.length + 1), newIndent);
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { ITextModel, IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
import { IIdentifiedSingleEditOperation, ITextModel } from 'vs/editor/common/model';
|
||||
|
||||
export class SortLinesCommand implements editorCommon.ICommand {
|
||||
|
||||
@@ -34,7 +33,11 @@ export class SortLinesCommand implements editorCommon.ICommand {
|
||||
return helper.getTrackedSelection(this.selectionId);
|
||||
}
|
||||
|
||||
public static canRun(model: ITextModel, selection: Selection, descending: boolean): boolean {
|
||||
public static canRun(model: ITextModel | null, selection: Selection, descending: boolean): boolean {
|
||||
if (model === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let data = getSortData(model, selection, descending);
|
||||
|
||||
if (!data) {
|
||||
@@ -64,7 +67,7 @@ function getSortData(model: ITextModel, selection: Selection, descending: boolea
|
||||
return null;
|
||||
}
|
||||
|
||||
let linesToSort = [];
|
||||
let linesToSort: string[] = [];
|
||||
|
||||
// Get the contents of the selection to be sorted.
|
||||
for (let lineNumber = startLineNumber; lineNumber <= endLineNumber; lineNumber++) {
|
||||
@@ -92,7 +95,7 @@ function getSortData(model: ITextModel, selection: Selection, descending: boolea
|
||||
/**
|
||||
* Generate commands for sorting lines on a model.
|
||||
*/
|
||||
function sortLines(model: ITextModel, selection: Selection, descending: boolean): IIdentifiedSingleEditOperation {
|
||||
function sortLines(model: ITextModel, selection: Selection, descending: boolean): IIdentifiedSingleEditOperation | null {
|
||||
let data = getSortData(model, selection, descending);
|
||||
|
||||
if (!data) {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { CopyLinesCommand } from 'vs/editor/contrib/linesOperations/copyLinesCommand';
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { DeleteLinesCommand } from 'vs/editor/contrib/linesOperations/deleteLinesCommand';
|
||||
import { testCommand } from 'vs/editor/test/browser/testCommand';
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
import { Cursor } from 'vs/editor/common/controller/cursor';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { Handler } from 'vs/editor/common/editorCommon';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { DeleteAllLeftAction, DeleteAllRightAction, IndentLinesAction, InsertLineAfterAction, InsertLineBeforeAction, JoinLinesAction, LowerCaseAction, SortLinesAscendingAction, SortLinesDescendingAction, TransposeAction, UpperCaseAction, DeleteLinesAction } from 'vs/editor/contrib/linesOperations/linesOperations';
|
||||
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { DeleteAllLeftAction, JoinLinesAction, TransposeAction, UpperCaseAction, LowerCaseAction, DeleteAllRightAction, InsertLineBeforeAction, InsertLineAfterAction, IndentLinesAction, SortLinesAscendingAction, SortLinesDescendingAction } from 'vs/editor/contrib/linesOperations/linesOperations';
|
||||
import { Cursor } from 'vs/editor/common/controller/cursor';
|
||||
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
import { createTextModel } from 'vs/editor/test/common/editorTestUtils';
|
||||
|
||||
suite('Editor Contrib - Line Operations', () => {
|
||||
@@ -447,7 +445,7 @@ suite('Editor Contrib - Line Operations', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('transpose', function () {
|
||||
test('transpose', () => {
|
||||
withTestCodeEditor(
|
||||
[
|
||||
'hello world',
|
||||
@@ -774,7 +772,7 @@ suite('Editor Contrib - Line Operations', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('InsertLineBeforeAction', function () {
|
||||
test('InsertLineBeforeAction', () => {
|
||||
function testInsertLineBefore(lineNumber: number, column: number, callback: (model: ITextModel, cursor: Cursor) => void): void {
|
||||
const TEXT = [
|
||||
'First line',
|
||||
@@ -881,4 +879,24 @@ suite('Editor Contrib - Line Operations', () => {
|
||||
|
||||
model.dispose();
|
||||
});
|
||||
|
||||
test('issue #62112: Delete line does not work properly when multiple cursors are on line', () => {
|
||||
const TEXT = [
|
||||
'a',
|
||||
'foo boo',
|
||||
'too',
|
||||
'c',
|
||||
];
|
||||
withTestCodeEditor(TEXT, {}, (editor, cursor) => {
|
||||
editor.setSelections([
|
||||
new Selection(2, 4, 2, 4),
|
||||
new Selection(2, 8, 2, 8),
|
||||
new Selection(3, 4, 3, 4),
|
||||
]);
|
||||
const deleteLinesAction = new DeleteLinesAction();
|
||||
deleteLinesAction.run(null, editor);
|
||||
|
||||
assert.equal(editor.getValue(), 'a\nc');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { MoveLinesCommand } from 'vs/editor/contrib/linesOperations/moveLinesCommand';
|
||||
import { testCommand } from 'vs/editor/test/browser/testCommand';
|
||||
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
|
||||
import { LanguageIdentifier } from 'vs/editor/common/modes';
|
||||
import { IndentationRule } from 'vs/editor/common/modes/languageConfiguration';
|
||||
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
|
||||
import { MoveLinesCommand } from 'vs/editor/contrib/linesOperations/moveLinesCommand';
|
||||
import { testCommand } from 'vs/editor/test/browser/testCommand';
|
||||
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
|
||||
|
||||
function testMoveLinesDownCommand(lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection): void {
|
||||
testCommand(lines, null, selection, (sel) => new MoveLinesCommand(sel, true, false), expectedLines, expectedSelection);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { SortLinesCommand } from 'vs/editor/contrib/linesOperations/sortLinesCommand';
|
||||
|
||||
Reference in New Issue
Block a user