Skip to content

Commit afd8f72

Browse files
Restructure
1 parent 37fe293 commit afd8f72

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ export function getSmartRemovalTarget(target: Target): Target {
1515
const { document } = editor;
1616
const contentRange = union(target.contentRange, target.prefixRange);
1717

18-
if (!isWholeLines(document, contentRange)) {
19-
return new TokenTarget({
20-
editor,
21-
isReversed,
22-
contentRange: contentRange,
23-
});
24-
}
18+
if (isWholeLines(document, contentRange)) {
19+
if (hasLeadingAndTrailingEmptyLines(document, contentRange)) {
20+
return new ParagraphTarget({
21+
editor,
22+
isReversed,
23+
contentRange: contentRange,
24+
});
25+
}
2526

26-
if (isParagraph(document, contentRange)) {
27-
return new ParagraphTarget({
27+
return new LineTarget({
2828
editor,
2929
isReversed,
3030
contentRange: contentRange,
3131
});
3232
}
3333

34-
return new LineTarget({
34+
return new TokenTarget({
3535
editor,
3636
isReversed,
3737
contentRange: contentRange,
@@ -56,7 +56,10 @@ function isWholeLines(document: TextDocument, contentRange: Range): boolean {
5656
/**
5757
* Returns whether the given content range is a paragraph (a series of whole lines bounded by whitespace or empty lines on each side).
5858
*/
59-
function isParagraph(document: TextDocument, contentRange: Range): boolean {
59+
function hasLeadingAndTrailingEmptyLines(
60+
document: TextDocument,
61+
contentRange: Range,
62+
): boolean {
6063
const { start, end } = contentRange;
6164
return (
6265
(start.line === 0 || document.lineAt(start.line - 1).isEmptyOrWhitespace) &&

0 commit comments

Comments
 (0)