mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-26 14:50:31 -04:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { ICommand, ICommonCodeEditor } from 'vs/editor/common/editorCommon';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
import { IActionOptions, editorAction, EditorAction, ServicesAccessor } from 'vs/editor/common/editorCommonExtensions';
|
||||
import { MoveCaretCommand } from './moveCaretCommand';
|
||||
|
||||
class MoveCaretAction extends EditorAction {
|
||||
|
||||
private left: boolean;
|
||||
|
||||
constructor(left: boolean, opts: IActionOptions) {
|
||||
super(opts);
|
||||
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
|
||||
|
||||
var commands: ICommand[] = [];
|
||||
var selections = editor.getSelections();
|
||||
|
||||
for (var i = 0; i < selections.length; i++) {
|
||||
commands.push(new MoveCaretCommand(selections[i], this.left));
|
||||
}
|
||||
|
||||
editor.pushUndoStop();
|
||||
editor.executeCommands(this.id, commands);
|
||||
editor.pushUndoStop();
|
||||
}
|
||||
}
|
||||
|
||||
@editorAction
|
||||
class MoveCaretLeftAction extends MoveCaretAction {
|
||||
constructor() {
|
||||
super(true, {
|
||||
id: 'editor.action.moveCarretLeftAction',
|
||||
label: nls.localize('caret.moveLeft', "Move Caret Left"),
|
||||
alias: 'Move Caret Left',
|
||||
precondition: EditorContextKeys.writable
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@editorAction
|
||||
class MoveCaretRightAction extends MoveCaretAction {
|
||||
constructor() {
|
||||
super(false, {
|
||||
id: 'editor.action.moveCarretRightAction',
|
||||
label: nls.localize('caret.moveRight', "Move Caret Right"),
|
||||
alias: 'Move Caret Right',
|
||||
precondition: EditorContextKeys.writable
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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';
|
||||
import { ICommand, ICursorStateComputerData, IEditOperationBuilder, ITokenizedModel } from 'vs/editor/common/editorCommon';
|
||||
|
||||
export class MoveCaretCommand implements ICommand {
|
||||
|
||||
private _selection: Selection;
|
||||
private _isMovingLeft: boolean;
|
||||
|
||||
private _cutStartIndex: number;
|
||||
private _cutEndIndex: number;
|
||||
private _moved: boolean;
|
||||
|
||||
private _selectionId: string;
|
||||
|
||||
constructor(selection: Selection, isMovingLeft: boolean) {
|
||||
this._selection = selection;
|
||||
this._isMovingLeft = isMovingLeft;
|
||||
}
|
||||
|
||||
public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
|
||||
var s = this._selection;
|
||||
this._selectionId = builder.trackSelection(s);
|
||||
if (s.startLineNumber !== s.endLineNumber) {
|
||||
return;
|
||||
}
|
||||
if (this._isMovingLeft && s.startColumn === 0) {
|
||||
return;
|
||||
} else if (!this._isMovingLeft && s.endColumn === model.getLineMaxColumn(s.startLineNumber)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var lineNumber = s.selectionStartLineNumber;
|
||||
var lineContent = model.getLineContent(lineNumber);
|
||||
|
||||
var left;
|
||||
var middle;
|
||||
var right;
|
||||
|
||||
if (this._isMovingLeft) {
|
||||
left = lineContent.substring(0, s.startColumn - 2);
|
||||
middle = lineContent.substring(s.startColumn - 1, s.endColumn - 1);
|
||||
right = lineContent.substring(s.startColumn - 2, s.startColumn - 1) + lineContent.substring(s.endColumn - 1);
|
||||
} else {
|
||||
left = lineContent.substring(0, s.startColumn - 1) + lineContent.substring(s.endColumn - 1, s.endColumn);
|
||||
middle = lineContent.substring(s.startColumn - 1, s.endColumn - 1);
|
||||
right = lineContent.substring(s.endColumn);
|
||||
}
|
||||
|
||||
var newLineContent = left + middle + right;
|
||||
|
||||
builder.addEditOperation(new Range(lineNumber, 1, lineNumber, model.getLineMaxColumn(lineNumber)), null);
|
||||
builder.addEditOperation(new Range(lineNumber, 1, lineNumber, 1), newLineContent);
|
||||
|
||||
this._cutStartIndex = s.startColumn + (this._isMovingLeft ? -1 : 1);
|
||||
this._cutEndIndex = this._cutStartIndex + s.endColumn - s.startColumn;
|
||||
this._moved = true;
|
||||
}
|
||||
|
||||
public computeCursorState(model: ITokenizedModel, helper: ICursorStateComputerData): Selection {
|
||||
var result = helper.getTrackedSelection(this._selectionId);
|
||||
if (this._moved) {
|
||||
result = result.setStartPosition(result.startLineNumber, this._cutStartIndex);
|
||||
result = result.setEndPosition(result.startLineNumber, this._cutEndIndex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
71
src/vs/editor/contrib/caretOperations/common/transpose.ts
Normal file
71
src/vs/editor/contrib/caretOperations/common/transpose.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 } from 'vs/base/common/keyCodes';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { ICommand, ICommonCodeEditor } from 'vs/editor/common/editorCommon';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
import { editorAction, EditorAction, ServicesAccessor } from 'vs/editor/common/editorCommonExtensions';
|
||||
import { ReplaceCommand } from 'vs/editor/common/commands/replaceCommand';
|
||||
|
||||
@editorAction
|
||||
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.textFocus,
|
||||
primary: 0,
|
||||
mac: {
|
||||
primary: KeyMod.WinCtrl | KeyCode.KEY_T
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
|
||||
let model = editor.getModel();
|
||||
let commands: ICommand[] = [];
|
||||
let selections = editor.getSelections();
|
||||
|
||||
for (let i = 0; i < selections.length; i++) {
|
||||
let selection = selections[i];
|
||||
if (!selection.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
let lineNumber = selection.startLineNumber;
|
||||
let column = selection.startColumn;
|
||||
if (column === 1) {
|
||||
// at the beginning of line
|
||||
continue;
|
||||
}
|
||||
let maxColumn = model.getLineMaxColumn(lineNumber);
|
||||
if (column === maxColumn) {
|
||||
// at the end of line
|
||||
continue;
|
||||
}
|
||||
|
||||
let lineContent = model.getLineContent(lineNumber);
|
||||
let charToTheLeft = lineContent.charAt(column - 2);
|
||||
let charToTheRight = lineContent.charAt(column - 1);
|
||||
|
||||
let replaceRange = new Range(lineNumber, column - 1, lineNumber, column + 1);
|
||||
|
||||
commands.push(new ReplaceCommand(replaceRange, charToTheRight + charToTheLeft));
|
||||
}
|
||||
|
||||
if (commands.length > 0) {
|
||||
editor.pushUndoStop();
|
||||
editor.executeCommands(this.id, commands);
|
||||
editor.pushUndoStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { MoveCaretCommand } from 'vs/editor/contrib/caretOperations/common/moveCaretCommand';
|
||||
import { testCommand } from 'vs/editor/test/common/commands/commandTestUtils';
|
||||
|
||||
|
||||
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)
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user