-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove word in command line with <C-w> (#4031)
* Remove word in command line with <C-w> Fixes #4027 * <C-w> only remove word before the cursor * Fix a typo * Fix the broken tests * Add unit tests for <C-w> in cmd line * Add <C-w> support in search mode * Add tests for <C-w> in search mode * Change runsOnceForEveryCursor of <C-w> cmd to return false
- Loading branch information
Showing
3 changed files
with
184 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import * as assert from 'assert'; | ||
import { getAndUpdateModeHandler } from '../../extension'; | ||
import { ModeHandler } from '../../src/mode/modeHandler'; | ||
import { StatusBar } from '../../src/statusBar'; | ||
import { cleanUpWorkspace, setupWorkspace } from '../testUtils'; | ||
|
||
suite('cmd_line/search command', () => { | ||
let modeHandler: ModeHandler; | ||
|
||
suiteSetup(async () => { | ||
await setupWorkspace(); | ||
modeHandler = await getAndUpdateModeHandler(); | ||
}); | ||
|
||
suiteTeardown(cleanUpWorkspace); | ||
|
||
test('command <C-w> can remove word in cmd line', async () => { | ||
await modeHandler.handleMultipleKeyEvents([':', 'a', 'b', 'c', '-', '1', '2', '3', '<C-w>']); | ||
let statusBar = StatusBar.Get().trim(); | ||
assert.equal(statusBar, ':abc-|', 'Failed to remove word'); | ||
|
||
await modeHandler.handleKeyEvent('<C-w>'); | ||
statusBar = StatusBar.Get().trim(); | ||
assert.equal(statusBar, ':abc|', 'Failed to remove word'); | ||
|
||
await modeHandler.handleKeyEvent('<C-w>'); | ||
statusBar = StatusBar.Get().trim(); | ||
assert.equal(statusBar, ':|', 'Failed to remove word'); | ||
|
||
await modeHandler.handleKeyEvent('<C-w>'); | ||
statusBar = StatusBar.Get().trim(); | ||
assert.equal(statusBar, ':|', 'Failed to remove word'); | ||
|
||
await modeHandler.handleKeyEvent('<Esc>'); | ||
}); | ||
|
||
test('command <C-w> can remove word in search mode', async () => { | ||
await modeHandler.handleMultipleKeyEvents(['/', 'a', 'b', 'c', '-', '1', '2', '3', '<C-w>']); | ||
let statusBar = StatusBar.Get().trim(); | ||
assert.equal(statusBar, '/abc-|', 'Failed to remove word'); | ||
|
||
await modeHandler.handleKeyEvent('<C-w>'); | ||
statusBar = StatusBar.Get().trim(); | ||
assert.equal(statusBar, '/abc|', 'Failed to remove word'); | ||
|
||
await modeHandler.handleKeyEvent('<C-w>'); | ||
statusBar = StatusBar.Get().trim(); | ||
assert.equal(statusBar, '/|', 'Failed to remove word'); | ||
|
||
await modeHandler.handleKeyEvent('<C-w>'); | ||
statusBar = StatusBar.Get().trim(); | ||
assert.equal(statusBar, '/|', 'Failed to remove word'); | ||
|
||
await modeHandler.handleKeyEvent('<Esc>'); | ||
}); | ||
|
||
test('command <C-w> can remove word in cmd line while retrain cmd on the right of the cursor', async () => { | ||
await modeHandler.handleMultipleKeyEvents([ | ||
':', | ||
'a', | ||
'b', | ||
'c', | ||
' ', | ||
'1', | ||
'2', | ||
'3', | ||
'<left>', | ||
'<left>', | ||
'<left>', | ||
'<C-w>', | ||
]); | ||
const statusBar = StatusBar.Get().trim(); | ||
assert.equal(statusBar, ':|123', 'Failed to retain the text on the right of the cursor'); | ||
await modeHandler.handleKeyEvent('<Esc>'); | ||
}); | ||
|
||
test('command <C-w> can remove word in search mode while retrain cmd on the right of the cursor', async () => { | ||
await modeHandler.handleMultipleKeyEvents([ | ||
'/', | ||
'a', | ||
'b', | ||
'c', | ||
' ', | ||
'1', | ||
'2', | ||
'3', | ||
'<left>', | ||
'<left>', | ||
'<left>', | ||
'<C-w>', | ||
]); | ||
const statusBar = StatusBar.Get().trim(); | ||
assert.equal(statusBar, '/|123', 'Failed to retain the text on the right of the cursor'); | ||
await modeHandler.handleKeyEvent('<Esc>'); | ||
}); | ||
}); |