Skip to content

Commit 018044b

Browse files
authored
Merge pull request #18 from cpmcgrath/develop
Version 2
2 parents ff01d31 + c0aad8e commit 018044b

6 files changed

Lines changed: 49 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
All notable changes to the "codealignment-vscode" extension will be documented in this file.
33

44
## [Unreleased]
5-
- #6 Allow Alignments from Caret Position
6-
- #8 Expose Align by Space
5+
6+
## 2.0 - 2018-01-28
7+
- Allow Alignments from Caret Position (Ticket 6)
8+
- Expose Align by Space (Ticket 8)
9+
- Change Align by equals delimiter to be a space then equals (Ticket 16)
10+
- Fixed: Automatic scope selection is used when column marking is used (Ticket 15)
711

812
## 1.2 - 2018-01-28
913
### Added
10-
- #10 Introduce key bindings
14+
- Introduce key bindings (Ticket 10)
1115

1216
## 1.0 - 2018-01-27
1317
### Added

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 1.2.{build}
1+
version: 2.0.{build}
22
image: Visual Studio 2017
33

44
platform:

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"onCommand:codealignment.alignbyequals",
1515
"onCommand:codealignment.alignbyperiod",
1616
"onCommand:codealignment.alignbyquote",
17-
"onCommand:codealignment.alignbyregex"
17+
"onCommand:codealignment.alignbyregex",
18+
"onCommand:codealignment.alignbyspace"
1819
],
1920
"main": "./out/extension",
2021
"contributes": {
@@ -23,13 +24,17 @@
2324
{ "command": "codealignment.alignbyequals", "title" : "Align by equals (Code Alignment)" },
2425
{ "command": "codealignment.alignbyperiod", "title" : "Align by period (Code Alignment)" },
2526
{ "command": "codealignment.alignbyquote", "title" : "Align by quote (Code Alignment)" },
26-
{ "command": "codealignment.alignbyregex", "title" : "Align by regex (Code Alignment)" }
27+
{ "command": "codealignment.alignbyregex", "title" : "Align by regex (Code Alignment)" },
28+
{ "command": "codealignment.alignbyspace", "title" : "Align by space (Code Alignment)" }
2729
],
2830
"keybindings" : [
29-
{ "command": "codealignment.alignbystring", "key": "ctrl+shift+=", "mac": "cmd+shift+=", "when": "editorTextFocus"},
30-
{ "command": "codealignment.alignbyequals", "key": "ctrl+= ctrl+=", "mac": "cmd+= cmd+=", "when": "editorTextFocus"},
31-
{ "command": "codealignment.alignbyperiod", "key": "ctrl+= ctrl+.", "mac": "cmd+= cmd+.", "when": "editorTextFocus"},
32-
{ "command": "codealignment.alignbyquote", "key": "ctrl+= ctrl+'", "mac": "cmd+= cmd+'", "when": "editorTextFocus"}
31+
{ "command": "codealignment.alignbystring", "key": "ctrl+shift+=", "mac": "cmd+shift+=", "when": "editorTextFocus"},
32+
{ "command": "codealignment.alignbyequals", "key": "ctrl+= ctrl+=", "mac": "cmd+= cmd+=", "when": "editorTextFocus"},
33+
{ "command": "codealignment.alignbyequalsfromcaret", "key": "ctrl+= ctrl+shift+=", "mac": "cmd+= cmd+shift+=", "when": "editorTextFocus"},
34+
{ "command": "codealignment.alignbyperiod", "key": "ctrl+= ctrl+.", "mac": "cmd+= cmd+.", "when": "editorTextFocus"},
35+
{ "command": "codealignment.alignbyquote", "key": "ctrl+= ctrl+'", "mac": "cmd+= cmd+'", "when": "editorTextFocus"},
36+
{ "command": "codealignment.alignbyquotefromcaret", "key": "ctrl+= ctrl+shift+'", "mac": "cmd+= cmd+shift+'", "when": "editorTextFocus"},
37+
{ "command": "codealignment.alignbyspace", "key": "ctrl+= ctrl+space", "mac": "cmd+= cmd+space", "when": "editorTextFocus"}
3338
]
3439
},
3540
"scripts": {

src/common/business/delimiterFinders/RegexDelimiterFinder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export class RegexDelimiterFinder extends NormalDelimiterFinder
1616
//var match = Regex.Match(source.substring(minIndex), delimiter);
1717
var match = source.substring(minIndex).match(delimiter);
1818

19-
if (match.length === 0)
19+
if (match === null)
2020
{
2121
return DelimiterResult.Create(-1);
2222
}
2323

2424
var result = new DelimiterResult();
25-
result.CompareIndex = minIndex + this.GetGroupIndex(match, "compare", "x"),
26-
result.InsertIndex = minIndex + this.GetGroupIndex(match, "insert", "compare", "x")
25+
result.CompareIndex = minIndex + this.GetGroupIndex(match, "compare", "x");
26+
result.InsertIndex = minIndex + this.GetGroupIndex(match, "insert", "compare", "x");
2727
return result;
2828
}
2929

src/extension.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,25 @@ import { GeneralScopeSelector } from './common/business/selectors/GeneralScopeSe
88
import { RegexDelimiterFinder } from './common/business/delimiterFinders/RegexDelimiterFinder';
99
import { 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

2532
function AlignByString()
@@ -51,11 +58,20 @@ function AlignByRegex()
5158
// your extension is activated the very first time the command is executed
5259
export 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

6177
export function deactivate()

src/implementation/Document.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ export class Document implements IDocument
1818

1919
public get StartSelectionLineNumber() : number
2020
{
21-
return this.m_editor.selection.start.line;
21+
return Math.min(...this.m_editor.selections.map(x => x.start.line));
2222
}
2323

2424
public get EndSelectionLineNumber() : number
2525
{
26-
return this.m_editor.selection.end.line;
26+
return Math.max(...this.m_editor.selections.map(x => x.end.line));
2727
}
2828

2929
public get CaretColumn() : number

0 commit comments

Comments
 (0)