@@ -8,18 +8,25 @@ import { GeneralScopeSelector } from './common/business/selectors/GeneralScopeSe
88import { RegexDelimiterFinder } from './common/business/delimiterFinders/RegexDelimiterFinder' ;
99import { Options } from './common/business/Options' ;
1010
11- function doAlignment ( delimiter : string , useRegex : boolean = false )
11+ function doAlignment ( delimiter : string , useRegex : boolean = false , fromCaret : boolean = false )
1212{
13- var alignment = new Alignment ( ) ;
13+ let alignment = new Alignment ( ) ;
1414 alignment . View = new Document ( vscode . window . activeTextEditor ) ;
15- var selector = new GeneralScopeSelector ( ) ;
15+ let selector = new GeneralScopeSelector ( ) ;
1616 selector . ScopeSelectorRegex = new Options ( ) . ScopeSelectorRegex ;
1717 alignment . Selector = selector ;
1818
1919 if ( useRegex )
2020 alignment . Finder = new RegexDelimiterFinder ( ) ;
2121
22- alignment . PerformAlignment ( delimiter , 0 , false ) ;
22+ let startIndex = 0 ;
23+ if ( fromCaret )
24+ {
25+ let position = vscode . window . activeTextEditor . selection . active ;
26+ startIndex = position . character ;
27+ }
28+
29+ alignment . PerformAlignment ( delimiter , startIndex , false ) ;
2330}
2431
2532function AlignByString ( )
@@ -51,11 +58,20 @@ function AlignByRegex()
5158// your extension is activated the very first time the command is executed
5259export function activate ( context : vscode . ExtensionContext )
5360{
54- context . subscriptions . push ( vscode . commands . registerCommand ( 'codealignment.alignbystring' , AlignByString ) ) ;
55- context . subscriptions . push ( vscode . commands . registerCommand ( 'codealignment.alignbyequals' , ( ) => doAlignment ( '=' ) ) ) ;
56- context . subscriptions . push ( vscode . commands . registerCommand ( 'codealignment.alignbyperiod' , ( ) => doAlignment ( '.' ) ) ) ;
57- context . subscriptions . push ( vscode . commands . registerCommand ( 'codealignment.alignbyquote' , ( ) => doAlignment ( '"' ) ) ) ;
58- context . subscriptions . push ( vscode . commands . registerCommand ( 'codealignment.alignbyregex' , AlignByRegex ) ) ;
61+ subscribeCommand ( context , 'codealignment.alignbystring' , AlignByString ) ;
62+ subscribeCommand ( context , 'codealignment.alignbyregex' , AlignByRegex ) ;
63+
64+ subscribeCommand ( context , 'codealignment.alignbyequals' , ( ) => doAlignment ( ' =' ) ) ;
65+ subscribeCommand ( context , 'codealignment.alignbyequalsfromcaret' , ( ) => doAlignment ( ' =' , false , true ) ) ;
66+ subscribeCommand ( context , 'codealignment.alignbyperiod' , ( ) => doAlignment ( '.' , false , true ) ) ;
67+ subscribeCommand ( context , 'codealignment.alignbyquote' , ( ) => doAlignment ( '"' ) ) ;
68+ subscribeCommand ( context , 'codealignment.alignbyquotefromcaret' , ( ) => doAlignment ( '"' , false , true ) ) ;
69+ subscribeCommand ( context , 'codealignment.alignbyspace' , ( ) => doAlignment ( "\\s[^\\s]" , true , true ) ) ;
70+ }
71+
72+ function subscribeCommand ( context : vscode . ExtensionContext , key : string , callback : ( ...args : any [ ] ) => any )
73+ {
74+ context . subscriptions . push ( vscode . commands . registerCommand ( key , callback ) ) ;
5975}
6076
6177export function deactivate ( )
0 commit comments