Skip to content

Commit a111baa

Browse files
committed
Make n and N act as failed motions at end/start of document with nowrapscan
Refs #4908
1 parent c3a938a commit a111baa

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/actions/motion.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ class CommandNextSearchMatch extends BaseMovement {
436436
keys = ['n'];
437437
isJump = true;
438438

439-
public async execAction(position: Position, vimState: VimState): Promise<Position> {
439+
public async execAction(position: Position, vimState: VimState): Promise<Position | IMovement> {
440440
const searchState = globalState.searchState;
441441

442442
if (!searchState || searchState.searchString === '') {
@@ -451,7 +451,7 @@ class CommandNextSearchMatch extends BaseMovement {
451451
vimState,
452452
VimError.fromCode(ErrorCode.PatternNotFound, searchState.searchString)
453453
);
454-
return position;
454+
return failedMovement(vimState);
455455
}
456456

457457
// we have to handle a special case here: searching for $ or \n,
@@ -474,7 +474,7 @@ class CommandNextSearchMatch extends BaseMovement {
474474
searchState.searchString
475475
)
476476
);
477-
return position;
477+
return failedMovement(vimState);
478478
}
479479

480480
reportSearch(nextMatch.index, searchState.getMatchRanges(vimState.editor).length, vimState);
@@ -488,7 +488,7 @@ class CommandPreviousSearchMatch extends BaseMovement {
488488
keys = ['N'];
489489
isJump = true;
490490

491-
public async execAction(position: Position, vimState: VimState): Promise<Position> {
491+
public async execAction(position: Position, vimState: VimState): Promise<Position | IMovement> {
492492
const searchState = globalState.searchState;
493493

494494
if (!searchState || searchState.searchString === '') {
@@ -503,7 +503,7 @@ class CommandPreviousSearchMatch extends BaseMovement {
503503
vimState,
504504
VimError.fromCode(ErrorCode.PatternNotFound, searchState.searchString)
505505
);
506-
return position;
506+
return failedMovement(vimState);
507507
}
508508

509509
const searchForward = searchState.searchDirection === SearchDirection.Forward;
@@ -533,7 +533,7 @@ class CommandPreviousSearchMatch extends BaseMovement {
533533
searchState.searchString
534534
)
535535
);
536-
return position;
536+
return failedMovement(vimState);
537537
}
538538

539539
reportSearch(prevMatch.index, searchState.getMatchRanges(vimState.editor).length, vimState);

test/macro.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,12 @@ suite('Record and execute a macro', () => {
105105
keysPressed: 'qajyyP<C-a>kq8@a',
106106
end: ['C|ountdown:', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1', 'LAUNCH!!!'],
107107
});
108+
109+
newTest({
110+
title: 'Failed `n` stops macro from repeating',
111+
config: { wrapscan: false },
112+
start: ['|one two three', 'one two three', 'one two three'],
113+
keysPressed: '/two\n0' + 'qq' + 'nea XXX<Esc>q' + '5@q',
114+
end: ['one two XXX three', 'one two XXX three', 'one two XX|X three'],
115+
});
108116
});

0 commit comments

Comments
 (0)