Skip to content

Commit

Permalink
Merge pull request #43 from chrsmutti/sort-entire-file
Browse files Browse the repository at this point in the history
Sort entire file if no text is selected
  • Loading branch information
Tyriar authored Nov 26, 2018
2 parents 2edaa20 + 0be7b55 commit bc4c255
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Sort lines of text in Visual Studio Code. The following types of sorting are sup

`{ "key": "f9", "command": "-sortLines.sortLines", "when": "editorTextFocus" }`

# Settings

| Name | Description | Default
|---|---|---|
| sortLines.filterBlankLines | _(boolean)_ Filter out blank (empty or whitespace-only) lines. | false
| sortLines.sortEntireFile | _(boolean)_ Sort entire file if no selection is active. | false

# Install

1. Open VS Code
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
"type": "boolean",
"default": false,
"description": "Filter out blank (empty or whitespace-only) lines."
},
"sortLines.sortEntireFile": {
"type": "boolean",
"default": false,
"description": "Sort entire file if no selection is active."
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions src/sort-lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ type SortingAlgorithm = (a: string, b: string) => number;
function sortActiveSelection(algorithm: SortingAlgorithm, removeDuplicateValues: boolean): Thenable<boolean> | undefined {
const textEditor = vscode.window.activeTextEditor;
const selection = textEditor.selection;

if (selection.isEmpty && vscode.workspace.getConfiguration('sortLines').get('sortEntireFile') === true) {
return sortLines(textEditor, 0, textEditor.document.lineCount - 1, algorithm, removeDuplicateValues);
}

if (selection.isSingleLine) {
return undefined;
}
Expand Down

0 comments on commit bc4c255

Please sign in to comment.