Skip to content

Commit 61d3bea

Browse files
Increment action cleanup (#3145)
1 parent 1786571 commit 61d3bea

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎packages/cursorless-engine/src/actions/incrementDecrement.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,9 @@ function formatNumberWithUnderscores(
173173
}
174174

175175
let resultWithUnderscores = updated;
176-
const signOffset =
177-
(updated[0] === "-" ? 1 : 0) - (original[0] === "-" ? 1 : 0);
178-
const intOffset =
179-
getIntegerPartLength(updated) -
180-
getIntegerPartLength(originalWithoutUnderscores);
181-
const offset = signOffset + intOffset;
176+
const offset =
177+
getIntegerAndSignPartLength(updated) -
178+
getIntegerAndSignPartLength(originalWithoutUnderscores);
182179

183180
for (const match of underscoreMatches) {
184181
const index = match.index + offset;
@@ -200,3 +197,7 @@ function hasLeadingZeros(text: string): boolean {
200197
function getIntegerPartLength(text: string): number {
201198
return /^-?(\d+)/.exec(text)![1].length;
202199
}
200+
201+
function getIntegerAndSignPartLength(text: string): number {
202+
return /^-?\d+/.exec(text)![0].length;
203+
}

0 commit comments

Comments
 (0)