From d6443ffc0e46e9fbc7eb262645c7cf17a5ea8c3b Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 1 Nov 2023 01:46:54 -0700 Subject: [PATCH] cull trimRange (#1898) It is unused. I believe that it also contains a latent bug, when the range contains entirely whitespace. Noticed during discussion at https://github.com/cursorless-dev/cursorless/pull/1854#discussion_r1327290730 ## 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> --- .../cursorless-engine/src/util/rangeUtils.ts | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/packages/cursorless-engine/src/util/rangeUtils.ts b/packages/cursorless-engine/src/util/rangeUtils.ts index 33d5def915..89bf2aebd3 100644 --- a/packages/cursorless-engine/src/util/rangeUtils.ts +++ b/packages/cursorless-engine/src/util/rangeUtils.ts @@ -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); @@ -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, - ), - ); -}