Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for <C-u> to clear line in prompt #11358

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
});