mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 2b0b9136329c181a9e381463a1f7dc3a2d105a34 (#4880)
This commit is contained in:
@@ -886,6 +886,8 @@ export abstract class AbstractCaseAction extends EditorAction {
|
||||
return;
|
||||
}
|
||||
|
||||
let wordSeparators = editor.getConfiguration().wordSeparators;
|
||||
|
||||
let commands: ICommand[] = [];
|
||||
|
||||
for (let i = 0, len = selections.length; i < len; i++) {
|
||||
@@ -900,12 +902,12 @@ export abstract class AbstractCaseAction extends EditorAction {
|
||||
|
||||
let wordRange = new Range(cursor.lineNumber, word.startColumn, cursor.lineNumber, word.endColumn);
|
||||
let text = model.getValueInRange(wordRange);
|
||||
commands.push(new ReplaceCommandThatPreservesSelection(wordRange, this._modifyText(text),
|
||||
commands.push(new ReplaceCommandThatPreservesSelection(wordRange, this._modifyText(text, wordSeparators),
|
||||
new Selection(cursor.lineNumber, cursor.column, cursor.lineNumber, cursor.column)));
|
||||
|
||||
} else {
|
||||
let text = model.getValueInRange(selection);
|
||||
commands.push(new ReplaceCommandThatPreservesSelection(selection, this._modifyText(text), selection));
|
||||
commands.push(new ReplaceCommandThatPreservesSelection(selection, this._modifyText(text, wordSeparators), selection));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -914,7 +916,7 @@ export abstract class AbstractCaseAction extends EditorAction {
|
||||
editor.pushUndoStop();
|
||||
}
|
||||
|
||||
protected abstract _modifyText(text: string): string;
|
||||
protected abstract _modifyText(text: string, wordSeparators: string): string;
|
||||
}
|
||||
|
||||
export class UpperCaseAction extends AbstractCaseAction {
|
||||
@@ -927,7 +929,7 @@ export class UpperCaseAction extends AbstractCaseAction {
|
||||
});
|
||||
}
|
||||
|
||||
protected _modifyText(text: string): string {
|
||||
protected _modifyText(text: string, wordSeparators: string): string {
|
||||
return text.toLocaleUpperCase();
|
||||
}
|
||||
}
|
||||
@@ -942,11 +944,48 @@ export class LowerCaseAction extends AbstractCaseAction {
|
||||
});
|
||||
}
|
||||
|
||||
protected _modifyText(text: string): string {
|
||||
protected _modifyText(text: string, wordSeparators: string): string {
|
||||
return text.toLocaleLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
export class TitleCaseAction extends AbstractCaseAction {
|
||||
constructor() {
|
||||
super({
|
||||
id: 'editor.action.transformToTitlecase',
|
||||
label: nls.localize('editor.transformToTitlecase', "Transform to Title Case"),
|
||||
alias: 'Transform to Title Case',
|
||||
precondition: EditorContextKeys.writable
|
||||
});
|
||||
}
|
||||
|
||||
protected _modifyText(text: string, wordSeparators: string): string {
|
||||
const separators = '\r\n\t ' + wordSeparators;
|
||||
const excludedChars = separators.split('');
|
||||
|
||||
let title = '';
|
||||
let startUpperCase = true;
|
||||
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
let currentChar = text[i];
|
||||
|
||||
if (excludedChars.indexOf(currentChar) >= 0) {
|
||||
startUpperCase = true;
|
||||
|
||||
title += currentChar;
|
||||
} else if (startUpperCase) {
|
||||
startUpperCase = false;
|
||||
|
||||
title += currentChar.toLocaleUpperCase();
|
||||
} else {
|
||||
title += currentChar.toLocaleLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
||||
registerEditorAction(CopyLinesUpAction);
|
||||
registerEditorAction(CopyLinesDownAction);
|
||||
registerEditorAction(MoveLinesUpAction);
|
||||
@@ -965,3 +1004,4 @@ registerEditorAction(JoinLinesAction);
|
||||
registerEditorAction(TransposeAction);
|
||||
registerEditorAction(UpperCaseAction);
|
||||
registerEditorAction(LowerCaseAction);
|
||||
registerEditorAction(TitleCaseAction);
|
||||
|
||||
@@ -9,7 +9,7 @@ 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 { TitleCaseAction, 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 { createTextModel } from 'vs/editor/test/common/editorTestUtils';
|
||||
|
||||
@@ -529,6 +529,7 @@ suite('Editor Contrib - Line Operations', () => {
|
||||
let model = editor.getModel()!;
|
||||
let uppercaseAction = new UpperCaseAction();
|
||||
let lowercaseAction = new LowerCaseAction();
|
||||
let titlecaseAction = new TitleCaseAction();
|
||||
|
||||
editor.setSelection(new Selection(1, 1, 1, 12));
|
||||
uppercaseAction.run(null!, editor);
|
||||
@@ -550,15 +551,63 @@ suite('Editor Contrib - Line Operations', () => {
|
||||
assert.equal(model.getLineContent(1), 'hello world', '007');
|
||||
assert.deepEqual(editor.getSelection()!.toString(), new Selection(1, 4, 1, 4).toString(), '008');
|
||||
|
||||
editor.setSelection(new Selection(1, 1, 1, 12));
|
||||
titlecaseAction.run(null!, editor);
|
||||
assert.equal(model.getLineContent(1), 'Hello World', '009');
|
||||
assert.deepEqual(editor.getSelection()!.toString(), new Selection(1, 1, 1, 12).toString(), '010');
|
||||
|
||||
editor.setSelection(new Selection(2, 1, 2, 6));
|
||||
uppercaseAction.run(null!, editor);
|
||||
assert.equal(model.getLineContent(2), 'ÖÇŞĞÜ', '009');
|
||||
assert.deepEqual(editor.getSelection()!.toString(), new Selection(2, 1, 2, 6).toString(), '010');
|
||||
assert.equal(model.getLineContent(2), 'ÖÇŞĞÜ', '011');
|
||||
assert.deepEqual(editor.getSelection()!.toString(), new Selection(2, 1, 2, 6).toString(), '012');
|
||||
|
||||
editor.setSelection(new Selection(2, 1, 2, 6));
|
||||
lowercaseAction.run(null!, editor);
|
||||
assert.equal(model.getLineContent(2), 'öçşğü', '011');
|
||||
assert.deepEqual(editor.getSelection()!.toString(), new Selection(2, 1, 2, 6).toString(), '012');
|
||||
assert.equal(model.getLineContent(2), 'öçşğü', '013');
|
||||
assert.deepEqual(editor.getSelection()!.toString(), new Selection(2, 1, 2, 6).toString(), '014');
|
||||
|
||||
editor.setSelection(new Selection(2, 1, 2, 6));
|
||||
titlecaseAction.run(null!, editor);
|
||||
assert.equal(model.getLineContent(2), 'Öçşğü', '015');
|
||||
assert.deepEqual(editor.getSelection()!.toString(), new Selection(2, 1, 2, 6).toString(), '016');
|
||||
}
|
||||
);
|
||||
|
||||
withTestCodeEditor(
|
||||
[
|
||||
'foO baR BaZ',
|
||||
'foO\'baR\'BaZ',
|
||||
'foO[baR]BaZ',
|
||||
'foO`baR~BaZ',
|
||||
'foO^baR%BaZ',
|
||||
'foO$baR!BaZ'
|
||||
], {}, (editor) => {
|
||||
let model = editor.getModel()!;
|
||||
let titlecaseAction = new TitleCaseAction();
|
||||
|
||||
editor.setSelection(new Selection(1, 1, 1, 12));
|
||||
titlecaseAction.run(null!, editor);
|
||||
assert.equal(model.getLineContent(1), 'Foo Bar Baz');
|
||||
|
||||
editor.setSelection(new Selection(2, 1, 2, 12));
|
||||
titlecaseAction.run(null!, editor);
|
||||
assert.equal(model.getLineContent(2), 'Foo\'Bar\'Baz');
|
||||
|
||||
editor.setSelection(new Selection(3, 1, 3, 12));
|
||||
titlecaseAction.run(null!, editor);
|
||||
assert.equal(model.getLineContent(3), 'Foo[Bar]Baz');
|
||||
|
||||
editor.setSelection(new Selection(4, 1, 4, 12));
|
||||
titlecaseAction.run(null!, editor);
|
||||
assert.equal(model.getLineContent(4), 'Foo`Bar~Baz');
|
||||
|
||||
editor.setSelection(new Selection(5, 1, 5, 12));
|
||||
titlecaseAction.run(null!, editor);
|
||||
assert.equal(model.getLineContent(5), 'Foo^Bar%Baz');
|
||||
|
||||
editor.setSelection(new Selection(6, 1, 6, 12));
|
||||
titlecaseAction.run(null!, editor);
|
||||
assert.equal(model.getLineContent(6), 'Foo$Bar!Baz');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user