Skip to content

Commit

Permalink
Make actions to transform case.
Browse files Browse the repository at this point in the history
  • Loading branch information
aioutecism committed Mar 10, 2017
1 parent f61796a commit 7c5a68b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
26 changes: 25 additions & 1 deletion src/Actions/Case.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {window, Range} from 'vscode';
import {commands, window, Range} from 'vscode';
import {StaticReflect} from '../LanguageExtensions/StaticReflect';
import {SymbolMetadata} from '../Symbols/Metadata';
import {ActionReveal} from './Reveal';
Expand All @@ -24,6 +24,30 @@ export class ActionCase {
.then(() => ActionReveal.primaryCursor());
}

@StaticReflect.metadata(SymbolMetadata.Action.isChange, true)
static lowercaseSelections(): Thenable<boolean> {
const activeTextEditor = window.activeTextEditor;

if (! activeTextEditor) {
return Promise.resolve(false);
}

return commands.executeCommand('editor.action.transformToLowercase')
.then(() => ActionReveal.primaryCursor());
}

@StaticReflect.metadata(SymbolMetadata.Action.isChange, true)
static uppercaseSelections(): Thenable<boolean> {
const activeTextEditor = window.activeTextEditor;

if (! activeTextEditor) {
return Promise.resolve(false);
}

return commands.executeCommand('editor.action.transformToUppercase')
.then(() => ActionReveal.primaryCursor());
}

@StaticReflect.metadata(SymbolMetadata.Action.isChange, true)
static switchActives(args: {n?: number}): Thenable<boolean> {
args.n = args.n === undefined ? 1 : args.n;
Expand Down
6 changes: 3 additions & 3 deletions src/Modes/Visual.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {commands, window} from 'vscode';
import {window} from 'vscode';
import {StaticReflect} from '../LanguageExtensions/StaticReflect';
import {SymbolMetadata} from '../Symbols/Metadata';
import {RangeOffset} from '../Types/RangeOffset';
Expand Down Expand Up @@ -87,11 +87,11 @@ export class ModeVisual extends Mode {
ActionSelection.shrinkToStarts,
] },
{ keys: 'u', actions: [
() => commands.executeCommand('editor.action.transformToLowercase'),
ActionCase.lowercaseSelections,
ActionSelection.shrinkToStarts,
] },
{ keys: 'U', actions: [
() => commands.executeCommand('editor.action.transformToUppercase'),
ActionCase.uppercaseSelections,
ActionSelection.shrinkToStarts,
] },

Expand Down
6 changes: 3 additions & 3 deletions src/Modes/VisualLine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {commands, window} from 'vscode';
import {window} from 'vscode';
import {StaticReflect} from '../LanguageExtensions/StaticReflect';
import {SymbolMetadata} from '../Symbols/Metadata';
import {RangeOffset} from '../Types/RangeOffset';
Expand Down Expand Up @@ -94,11 +94,11 @@ export class ModeVisualLine extends Mode {
ActionSelection.shrinkToStarts,
] },
{ keys: 'u', actions: [
() => commands.executeCommand('editor.action.transformToLowercase'),
ActionCase.lowercaseSelections,
ActionSelection.shrinkToStarts,
] },
{ keys: 'U', actions: [
() => commands.executeCommand('editor.action.transformToUppercase'),
ActionCase.uppercaseSelections,
ActionSelection.shrinkToStarts,
] },

Expand Down

0 comments on commit 7c5a68b

Please sign in to comment.