mirror of
https://github.com/VSCodeVim/Vim.git
synced 2024-09-11 20:27:17 +03:00
<C-r> <C-w> (insert word under cursor) in search/commmand line (#4143)
* <C-r> <C-w> (insert word under cursor) in search/commmand line fixes #4102
This commit is contained in:
parent
5d067f4e96
commit
66d507bb3d
@ -419,6 +419,33 @@ class CommandInsertRegisterContentInSearchMode extends BaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterAction
|
||||
class CommandInsertWord extends BaseCommand {
|
||||
modes = [ModeName.CommandlineInProgress, ModeName.SearchInProgressMode];
|
||||
keys = ['<C-r>', '<C-w>'];
|
||||
|
||||
public async exec(position: Position, vimState: VimState): Promise<VimState> {
|
||||
// Skip forward to next word, not going past EOL
|
||||
while (!/[a-zA-Z0-9_]/.test(TextEditor.getCharAt(position))) {
|
||||
position = position.getRight();
|
||||
}
|
||||
const word = TextEditor.getWord(position.getLeftIfEOL());
|
||||
|
||||
if (word !== undefined) {
|
||||
if (vimState.currentMode === ModeName.SearchInProgressMode) {
|
||||
const searchState = globalState.searchState!;
|
||||
searchState.searchString += word;
|
||||
} else {
|
||||
vimState.currentCommandlineText += word;
|
||||
}
|
||||
|
||||
vimState.statusBarCursorCharacterPos += word.length;
|
||||
}
|
||||
|
||||
return vimState;
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterAction
|
||||
class CommandRecordMacro extends BaseCommand {
|
||||
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine];
|
||||
|
@ -155,4 +155,25 @@ suite('cmd_line/search command', () => {
|
||||
assert.strictEqual(StatusBar.Get().trim(), ':|');
|
||||
await modeHandler.handleKeyEvent('<Esc>');
|
||||
});
|
||||
|
||||
test('<C-r> <C-w> insert word under cursor on command line', async () => {
|
||||
await modeHandler.handleMultipleKeyEvents('iabc'.split(''));
|
||||
await modeHandler.handleMultipleKeyEvents(['<Esc>', ':', '<C-r>', '<C-w>']);
|
||||
const statusBar = StatusBar.Get().trim();
|
||||
assert.equal(statusBar, ':abc|', 'Failed to insert word');
|
||||
});
|
||||
|
||||
test('<C-r> <C-w> insert right word of cursor on command line', async () => {
|
||||
await modeHandler.handleMultipleKeyEvents('i::abc'.split(''));
|
||||
await modeHandler.handleMultipleKeyEvents(['<Esc>', '0', ':', '<C-r>', '<C-w>']);
|
||||
const statusBar = StatusBar.Get().trim();
|
||||
assert.equal(statusBar, ':abc|', 'Failed to insert word');
|
||||
});
|
||||
|
||||
test('<C-r> <C-w> insert word under cursor in search mode', async () => {
|
||||
await modeHandler.handleMultipleKeyEvents('iabc'.split(''));
|
||||
await modeHandler.handleMultipleKeyEvents(['<Esc>', '/', '<C-r>', '<C-w>']);
|
||||
const statusBar = StatusBar.Get().trim();
|
||||
assert.equal(statusBar, '/abc|', 'Failed to insert word');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user