Skip to content

Commit c85cd8c

Browse files
committed
fix(extension): trim hanging cursors at start or end of line from selection
1 parent 6a932c8 commit c85cd8c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/providers/BlockSortFormattingProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ export default class BlockSortFormattingProvider
121121
): Range {
122122
if (!this.isAttached(document)) this.attachDocument(document, token);
123123
const blockSort = this.blockSortProviders.get(document.uri)!;
124-
const initialRange = "start" in selection ? selection : new Range(selection, selection);
124+
const initialRange = blockSort.trimRange(
125+
"start" in selection ? selection : new Range(selection, selection)
126+
);
125127

126128
if (options.expandSelection === false) return initialRange;
127129

src/providers/BlockSortProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ export default class BlockSortProvider implements Disposable {
338338
let start = selection.start.line;
339339
let end = selection.end.line;
340340

341+
if (start < end && selection.start.character >= this.document.lineAt(start).text.length) start++;
342+
if (end > start && selection.end.character === 0) end--;
343+
341344
while (start < end && this.document.lineAt(start).isEmptyOrWhitespace) start++;
342345
while (end > start && this.document.lineAt(end).isEmptyOrWhitespace) end--;
343346

0 commit comments

Comments
 (0)