Skip to content

Commit 49188c3

Browse files
authored
feat: add support for <C-u> to clear line in prompt (#11358)
1 parent dae3641 commit 49188c3

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- `[jest-transform]` [**BREAKING**] Do not export `ScriptTransformer` class, instead export the async function `createScriptTransformer` ([#11163](https://github.com/facebook/jest/pull/11163))
3838
- `[jest-transform]` Async code transformations ([#9889](https://github.com/facebook/jest/pull/9889))
3939
- `[jest-transform]` Support transpiled transformers ([#11193](https://github.com/facebook/jest/pull/11193))
40+
- `[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))
4041
- `[jest-worker]` Add support for custom task queues and adds a `PriorityQueue` implementation. ([#10921](https://github.com/facebook/jest/pull/10921))
4142
- `[jest-worker]` Add in-order scheduling policy to jest worker ([10902](https://github.com/facebook/jest/pull/10902))
4243
- `[pretty-format]` Better print for sparse arrays ([11326](https://github.com/facebook/jest/pull/11326))

packages/jest-watcher/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const KEYS = {
1515
BACKSPACE: Buffer.from(isWindows ? '08' : '7f', 'hex').toString(),
1616
CONTROL_C: '\u0003',
1717
CONTROL_D: '\u0004',
18+
CONTROL_U: '\u0015',
1819
ENTER: '\r',
1920
ESCAPE: '\u001b',
2021
};

packages/jest-watcher/src/lib/Prompt.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ export default class Prompt {
8989
case KEYS.ARROW_LEFT:
9090
case KEYS.ARROW_RIGHT:
9191
break;
92+
case KEYS.CONTROL_U:
93+
this._value = '';
94+
this._offset = -1;
95+
this._selection = null;
96+
this._onChange();
97+
break;
9298
default:
9399
this._value =
94100
key === KEYS.BACKSPACE ? this._value.slice(0, -1) : this._value + key;

packages/jest-watcher/src/lib/__tests__/prompt.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,20 @@ it('calls handler on cancel prompt', () => {
6262

6363
expect(onCancel).toHaveBeenCalled();
6464
});
65+
66+
it('clears the line when CONTROL_U is pressed', () => {
67+
const prompt = new Prompt();
68+
const onChange = jest.fn();
69+
const options = {max: 10, offset: -1};
70+
71+
prompt.enter(onChange, jest.fn(), jest.fn());
72+
73+
prompt.put('t');
74+
prompt.put('e');
75+
prompt.put('s');
76+
prompt.put('t');
77+
expect(onChange).toHaveBeenLastCalledWith('test', options);
78+
79+
prompt.put(KEYS.CONTROL_U);
80+
expect(onChange).toHaveBeenLastCalledWith('', options);
81+
});

0 commit comments

Comments
 (0)