Skip to content

Commit

Permalink
fix: fix selections with empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
1nVitr0 committed Mar 21, 2021
1 parent 2354e32 commit d6195cd
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/providers/BlockSortProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export default class BlockSortProvider {
let lastStart = 0;
let currentEnd = 0;
for (const line of lines) {
if (this.isValidLine(line) && this.getIndent(line) === initialIndent && !this.hasFolding(folding)) {
if (
this.isValidLine(line) &&
!this.isIndentIgnoreLine(line) &&
this.getIndent(line) === initialIndent &&
!this.hasFolding(folding)
) {
blocks.push(
this.document.validateRange(
new Range(range.start.line + lastStart, 0, range.start.line + currentEnd, Infinity)
Expand Down Expand Up @@ -116,6 +121,14 @@ export default class BlockSortProvider {
range = new Range(range.start.line, 0, range.end.line + 1, Infinity);
range = new Range(range.start.line, 0, range.end.line - 1, Infinity);

while (
range.start.line <= range.end.line &&
this.isIndentIgnoreLine(
this.document.getText(range.with(range.start, range.start.with(range.start.line, Infinity)))
)
)
range = range.with(range.start.with(range.start.line + 1, 0));

return this.document.validateRange(range);
}

Expand All @@ -127,6 +140,7 @@ export default class BlockSortProvider {
let max = 0;

for (const line of lines) {
if (this.isIndentIgnoreLine(line)) continue;
const indent = this.getIndent(line, indentWidth);
if (indent < min) min = indent;
if (indent > max) max = indent;
Expand Down Expand Up @@ -177,6 +191,10 @@ export default class BlockSortProvider {
return Array.from(first).pop() === ',';
}

private isIndentIgnoreLine(line: string): boolean {
return /^\s*$/.test(line) || /^\s*(private|protected|public):\s*(\/\/.*|\/\*\.*\*\/)?/.test(line);
}

private isValidLine(line: string): boolean {
return !/^\s*$/.test(line) && !/^\s*(@|{)/.test(line);
}
Expand Down

0 comments on commit d6195cd

Please sign in to comment.