Skip to content

Commit

Permalink
cull trimRange (#1898)
Browse files Browse the repository at this point in the history
It is unused. I believe that it also contains a latent bug,
when the range contains entirely whitespace.

Noticed during discussion at


#1854 (comment)



## Checklist

- [-] I have added
[tests](https://www.cursorless.org/docs/contributing/test-case-recorder/)
- [-] I have updated the
[docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and
[cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet)
- [-] I have not broken the cheatsheet

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
josharian and pre-commit-ci-lite[bot] authored Nov 1, 2023
1 parent 9730ac5 commit d6443ff
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions packages/cursorless-engine/src/util/rangeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Position, Range, TextEditor } from "@cursorless/common";
import { getLeadingWhitespace, getTrailingWhitespace } from "./regex";

export function isAtEndOfLine(editor: TextEditor, position: Position) {
const endLine = editor.document.lineAt(position);
Expand Down Expand Up @@ -54,30 +53,3 @@ export function strictlyContains(
: [rangeOrPosition.start, rangeOrPosition.end];
return range1.start.isBefore(start) && range1.end.isAfter(end);
}

/**
* Trim the given range of whitespaces
* @param editor The editor to get the text from
* @param range The range to trim
*/
export function trimRange(editor: TextEditor, range: Range): Range {
const text = editor.document.getText(range);
const leadingWhitespace = getLeadingWhitespace(text);
const trailingWhitespace = getTrailingWhitespace(text);

if (leadingWhitespace === "" && trailingWhitespace === "") {
return range;
}

const startOffset =
editor.document.offsetAt(range.start) + leadingWhitespace.length;
return new Range(
editor.document.positionAt(startOffset),
editor.document.positionAt(
startOffset +
text.length -
leadingWhitespace.length -
trailingWhitespace.length,
),
);
}

0 comments on commit d6443ff

Please sign in to comment.