Skip to content

Commit

Permalink
Bugfix: subsection motions can move by start without skipping a subse…
Browse files Browse the repository at this point in the history
…ction (#55)

Some subection motion would previously skip selecting the current
section when `selectWhole = true`, `value = 1` and `unit = 'start'`.

This fixes the issue by always checking if
we need the unit boundary that occurs just before the cursor when
resolving the unit boundaries.
  • Loading branch information
haberdashPI authored Sep 19, 2024
1 parent 5eb4026 commit b115c42
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publisher": "haberdashPI",
"repository": "https://github.com/haberdashPI/vscode-selection-utilities",
"description": "Kakaune-inspired collection of useful commands for manipulating selections.",
"version": "0.6.7",
"version": "0.6.6",
"icon": "logo.png",
"engines": {
"vscode": "^1.92.0"
Expand Down Expand Up @@ -465,4 +465,4 @@
"@wdio/spec-reporter": "^8.40.3",
"ts-node": "^10.9.2"
}
}
}
4 changes: 2 additions & 2 deletions src/web/unitMotions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ function* resolveUnitBoundaries(
): Generator<Range> {
let backwards: Generator<Range>;
function* resolveHelper(firstUnit: Range, back: Range): Generator<Range> {
if (resolve === Boundary.Start && (!firstUnit?.start || !forward)) {
if (resolve === Boundary.Start) {
if (forward) {
if (!firstUnit?.start) {
firstUnit = fuseRanges(firstUnit, back);
Expand All @@ -465,7 +465,7 @@ function* resolveUnitBoundaries(
}
yield firstUnit;
}
} else if (resolve === Boundary.End && (!firstUnit?.end || forward)) {
} else if (resolve === Boundary.End) {
if (!forward) {
if (!firstUnit?.end) {
firstUnit = fuseRanges(firstUnit, back);
Expand Down
36 changes: 36 additions & 0 deletions test/specs/moveBySection.ux.mts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ describe('Section Motion', () => {
`
);

await editor.moveCursor(10, 1);
await parMoveSelects(
{selectWhole: true, boundary: 'start'},
`# B
# --------------------
billybob
bim
`
);
});

it('Can move by end', async () => {
Expand All @@ -117,6 +129,19 @@ describe('Section Motion', () => {
# B
# --------------------`
);

await editor.moveCursor(9, 1);

await parMoveSelects(
{selectWhole: true, boundary: 'end'},
`
billybob
bim
# A.2
# --------------------`
);
});

it('Can move backwards by start', async () => {
Expand All @@ -137,6 +162,17 @@ describe('Section Motion', () => {
it('Can move backwards by end', async () => {
await editor.moveCursor(9, 1);

await parMoveSelects(
{selectWhole: true, boundary: 'end', value: -1},
`
billybob
bim
# A.2
# --------------------`
);

await parMoveSelects(
{selectWhole: true, boundary: 'end', value: -1},
`
Expand Down

0 comments on commit b115c42

Please sign in to comment.