Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uppercase support #349

Merged
merged 2 commits into from
Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,15 +656,7 @@ export class DeleteOperator extends BaseOperator {
* Deletes from the position of start to 1 past the position of end.
*/
public async run(vimState: VimState, start: Position, end: Position): Promise<VimState> {
if (start.compareTo(end) <= 0) {
end = new Position(end.line, end.character + 1);
} else {
const tmp = start;
start = end;
end = tmp;

end = new Position(end.line, end.character + 1);
}
end = new Position(end.line, end.character + 1);

const isOnLastLine = end.line === TextEditor.getLineCount() - 1;

Expand Down Expand Up @@ -770,6 +762,23 @@ export class DeleteOperatorXVisual extends BaseOperator {
}
}

@RegisterAction
export class UpperCaseOperator extends BaseOperator {
public keys = ["U"];
public modes = [ModeName.Visual, ModeName.VisualLine];

public async run(vimState: VimState, start: Position, end: Position): Promise<VimState> {
end = new Position(end.line, end.character + 1);

let text = vscode.window.activeTextEditor.document.getText(new vscode.Range(start, end));

await TextEditor.replace(new vscode.Range(start, end), text.toUpperCase());
vimState.currentMode = ModeName.Normal;

return vimState;
}
}

@RegisterAction
export class ChangeOperator extends BaseOperator {
public keys = ["c"];
Expand Down
8 changes: 4 additions & 4 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,11 @@ export class ModeHandler implements vscode.Disposable {
}
}

if (this.currentModeName === ModeName.VisualLine) {
if (Position.EarlierOf(start, stop) === stop) {
[start, stop] = [stop, start];
}
if (start.compareTo(stop) > 0) {
[start, stop] = [stop, start];
}

if (this.currentModeName === ModeName.VisualLine) {
start = start.getLineBegin();
stop = stop.getLineEnd();

Expand Down
36 changes: 36 additions & 0 deletions test/mode/modeVisualLine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ suite("Mode Visual", () => {
assertEqual(modeHandler.currentMode.name, ModeName.Normal);
});

test("Can handle U", async () => {
await modeHandler.handleMultipleKeyEvents("ione two three".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', '^',
'v', 'U'
]);

assertEqualLines(["One two three"]);

assertEqual(modeHandler.currentMode.name, ModeName.Normal);
})

test("Can handle x across a selection", async () => {
await modeHandler.handleMultipleKeyEvents("ione two three".split(""));
await modeHandler.handleMultipleKeyEvents([
Expand Down Expand Up @@ -110,6 +122,30 @@ suite("Mode Visual", () => {
assertEqualLines(["our"]);
});

test("Can handle U across a selection", async () => {
await modeHandler.handleMultipleKeyEvents("ione two three".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', '^',
'v', 'l', 'l', 'l', 'l', 'U'
]);

assertEqualLines(["ONE Two three"]);

assertEqual(modeHandler.currentMode.name, ModeName.Normal);
});

test("Can handle U across a selection in reverse order", async () => {
await modeHandler.handleMultipleKeyEvents("ione two three".split(""));
await modeHandler.handleMultipleKeyEvents([
'<esc>', '^',
'w', 'v', 'h', 'h', 'U'
]);

assertEqualLines(["onE Two three"]);

assertEqual(modeHandler.currentMode.name, ModeName.Normal);
});

test("handles case where we go from selecting on right side to selecting on left side", async () => {
await modeHandler.handleMultipleKeyEvents("ione two three".split(""));
await modeHandler.handleMultipleKeyEvents([
Expand Down