Skip to content

Commit

Permalink
feat: add support for <C-u> to clear line in prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
parthsharma2 committed Apr 29, 2021
1 parent c5e2a59 commit 93a2b52
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -36,6 +36,7 @@
- `[jest-transform]` [**BREAKING**] Do not export `ScriptTransformer` class, instead export the async function `createScriptTransformer` ([#11163](https://github.com/facebook/jest/pull/11163))
- `[jest-transform]` Async code transformations ([#9889](https://github.com/facebook/jest/pull/9889))
- `[jest-transform]` Support transpiled transformers ([#11193](https://github.com/facebook/jest/pull/11193))
- `[jest-watcher]` Added support for clearing the line when `<C-u>` is pressed in a watch mode pattern prompt ([#11358](https://github.com/facebook/jest/pull/11358))
- `[jest-worker]` Add support for custom task queues and adds a `PriorityQueue` implementation. ([#10921](https://github.com/facebook/jest/pull/10921))
- `[jest-worker]` Add in-order scheduling policy to jest worker ([10902](https://github.com/facebook/jest/pull/10902))
- `[pretty-format]` Better print for sparse arrays ([11326](https://github.com/facebook/jest/pull/11326))
Expand Down
1 change: 1 addition & 0 deletions packages/jest-watcher/src/constants.ts
Expand Up @@ -15,6 +15,7 @@ export const KEYS = {
BACKSPACE: Buffer.from(isWindows ? '08' : '7f', 'hex').toString(),
CONTROL_C: '\u0003',
CONTROL_D: '\u0004',
CONTROL_U: '\u0015',
ENTER: '\r',
ESCAPE: '\u001b',
};
6 changes: 6 additions & 0 deletions packages/jest-watcher/src/lib/Prompt.ts
Expand Up @@ -89,6 +89,12 @@ export default class Prompt {
case KEYS.ARROW_LEFT:
case KEYS.ARROW_RIGHT:
break;
case KEYS.CONTROL_U:
this._value = '';
this._offset = -1;
this._selection = null;
this._onChange();
break;
default:
this._value =
key === KEYS.BACKSPACE ? this._value.slice(0, -1) : this._value + key;
Expand Down
17 changes: 17 additions & 0 deletions packages/jest-watcher/src/lib/__tests__/prompt.test.ts
Expand Up @@ -62,3 +62,20 @@ it('calls handler on cancel prompt', () => {

expect(onCancel).toHaveBeenCalled();
});

it('clears the line when CONTROL_U is pressed', () => {
const prompt = new Prompt();
const onChange = jest.fn();
const options = {max: 10, offset: -1};

prompt.enter(onChange, jest.fn(), jest.fn());

prompt.put('t');
prompt.put('e');
prompt.put('s');
prompt.put('t');
expect(onChange).toHaveBeenLastCalledWith('test', options);

prompt.put(KEYS.CONTROL_U);
expect(onChange).toHaveBeenLastCalledWith('', options);
});

0 comments on commit 93a2b52

Please sign in to comment.