Skip to content

Commit

Permalink
Bugfix: moveBy extend unit in middle of unit edge cases (#66)
Browse files Browse the repository at this point in the history
Fixes some edge-case behavior around how units are moved when extending
a selection
  • Loading branch information
haberdashPI authored Nov 10, 2024
1 parent 0ee60e2 commit 0c58b24
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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.9",
"version": "0.6.10",
"icon": "logo.png",
"engines": {
"vscode": "^1.92.0"
Expand Down
4 changes: 2 additions & 2 deletions src/web/unitMotions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,9 @@ function moveBy(editor: vscode.TextEditor, args: MoveByArgs) {
let startSel: vscode.Position | undefined = undefined;
for (const sel of selections) {
if (count > 0 || !boundsMatch(sel, select)) {
if (forward && sel.end.isAfter(select.active)) {
if (forward && sel.active.isAfter(select.active)) {
count += 1;
} else if (!forward && sel.start.isBefore(select.active)) {
} else if (!forward && sel.active.isBefore(select.active)) {
count += 1;
}
if (count === 1) {
Expand Down
32 changes: 30 additions & 2 deletions test/specs/moveBySubword.ux.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@wdio/globals';
import 'wdio-vscode-service';
import {setupEditor, storeCoverageStats, waitUntilCursorUnmoving} from './utils.mts';
import {TextEditor} from 'wdio-vscode-service';
import {sleep, TextEditor} from 'wdio-vscode-service';

describe('Subword Motion', () => {
let editor: TextEditor;
Expand Down Expand Up @@ -73,27 +73,55 @@ describe('Subword Motion', () => {

await wordMoveSelects({select: true, boundary: 'start'}, 'oo ');
await wordMoveSelects({select: true, boundary: 'start'}, 'oo bar ');
await browser.executeWorkbench(async vscode => {
await vscode.commands.executeCommand(
'selection-utilities.exchangeAnchorActive'
);
});
await sleep(100);
await wordMoveSelects({select: true, boundary: 'start'}, 'bar ');
});

it('Can extend forward by end', async () => {
await editor.moveCursor(1, 2);

await wordMoveSelects({select: true, boundary: 'end'}, 'oo');
await wordMoveSelects({select: true, boundary: 'end'}, 'oo bar');
await browser.executeWorkbench(async vscode => {
await vscode.commands.executeCommand(
'selection-utilities.exchangeAnchorActive'
);
});
await sleep(100);
await wordMoveSelects({select: true, boundary: 'end'}, ' bar');
});

it('Can extend bakcwards by start', async () => {
await editor.moveCursor(1, 7);

await wordMoveSelects({select: true, boundary: 'start', value: -1}, 'ba');
await wordMoveSelects({select: true, boundary: 'start', value: -1}, 'foo ba');
await browser.executeWorkbench(async vscode => {
await vscode.commands.executeCommand(
'selection-utilities.exchangeAnchorActive'
);
});
await sleep(100);
await wordMoveSelects({select: true, boundary: 'start', value: -1}, 'foo ');
});

it('Can extend bakcwards by end', async () => {
it('Can extend backwards by end', async () => {
await editor.moveCursor(1, 7);

await wordMoveSelects({select: true, boundary: 'end', value: -1}, ' ba');
await wordMoveSelects({select: true, boundary: 'end', value: -1}, 'foo ba');
await browser.executeWorkbench(async vscode => {
await vscode.commands.executeCommand(
'selection-utilities.exchangeAnchorActive'
);
});
await sleep(100);
await wordMoveSelects({select: true, boundary: 'end', value: -1}, 'foo');
});

it('Can extend to "start" at file end', async () => {
Expand Down
1 change: 1 addition & 0 deletions wdio.conf.mts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const config: Options.Testrunner = {
browserVersion: 'stable', // also possible: "insiders" or a specific version e.g. "1.80.0"
'wdio:vscodeOptions': {
// points to directory where extension package.json is located
version: '1.93.0',
extensionPath: __dirname,
workspacePath: __dirname,
vscodeArgs: {
Expand Down

0 comments on commit 0c58b24

Please sign in to comment.