Skip to content
Open
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
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,27 @@
"Other"
],
"engines": {
"vscode": "^1.0.0"
"vscode": "^1.1.18"
},
"activationEvents": [
"onCommand:extension.insertNumbers"
],
"main": "./out/src/extension",
"contributes": {
"commands": [{
"command": "extension.insertNumbers",
"title": "Insert Numbers"
}],

"keybindings": [{
"command": "extension.insertNumbers",
"key": "ctrl+alt+n",
"mac": "cmd+alt+n",
"when": "editorTextFocus"
}]
"commands": [
{
"command": "extension.insertNumbers",
"title": "Insert Numbers"
}
],
"keybindings": [
{
"command": "extension.insertNumbers",
"key": "ctrl+alt+n",
"mac": "cmd+alt+n",
"when": "editorTextFocus"
}
]
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
Expand All @@ -51,4 +54,4 @@
"typescript": "^1.8.5",
"vscode": "^0.11.0"
}
}
}
32 changes: 31 additions & 1 deletion src/NumInserter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class NumInserter
{
let textEditor = vscode.window.activeTextEditor;

const selections : vscode.Selection[] = textEditor.selections;
const selections : vscode.Selection[] = this.quickSort(textEditor.selections);

const formatStr = settings.formatStr;
const start = settings.start;
Expand All @@ -110,6 +110,36 @@ export class NumInserter
}
)
}

private quickSort(selections : vscode.Selection[]) : vscode.Selection[]
{
let middleIndex : number = selections.length >> 1;
if (selections.length <= 1) {
return selections;
}
let middle : vscode.Selection = selections[middleIndex];
let left : vscode.Selection[] = [];
let right : vscode.Selection[] = [];
for (var i=0; i<selections.length; i++){
if(i==middleIndex){
continue;
}
let current : vscode.Selection = selections[i];
if (current.start.line < middle.start.line) {
left.push(current);
} else if (current.start.line > middle.start.line) {
right.push(current);
} else {
if (current.start.character <= middle.start.character) {
left.push(current);
} else {
right.push(current);
}
}

}
return this.quickSort(left).concat([middle], this.quickSort(right));
}

private parseUserInput(input : string) : IInsertSettngs
{
Expand Down