Add back support for escaping newline with a \ character (#4064)
This commit is contained in:
parent
b018e2d3ad
commit
ef8ec98489
|
@ -90,6 +90,7 @@ describe('InputPrompt', () => {
|
||||||
killLineLeft: vi.fn(),
|
killLineLeft: vi.fn(),
|
||||||
openInExternalEditor: vi.fn(),
|
openInExternalEditor: vi.fn(),
|
||||||
newline: vi.fn(),
|
newline: vi.fn(),
|
||||||
|
backspace: vi.fn(),
|
||||||
} as unknown as TextBuffer;
|
} as unknown as TextBuffer;
|
||||||
|
|
||||||
mockShellHistory = {
|
mockShellHistory = {
|
||||||
|
@ -527,4 +528,19 @@ describe('InputPrompt', () => {
|
||||||
expect(props.onSubmit).not.toHaveBeenCalled();
|
expect(props.onSubmit).not.toHaveBeenCalled();
|
||||||
unmount();
|
unmount();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should add a newline on enter when the line ends with a backslash', async () => {
|
||||||
|
props.buffer.setText('first line\\');
|
||||||
|
|
||||||
|
const { stdin, unmount } = render(<InputPrompt {...props} />);
|
||||||
|
await wait();
|
||||||
|
|
||||||
|
stdin.write('\r');
|
||||||
|
await wait();
|
||||||
|
|
||||||
|
expect(props.onSubmit).not.toHaveBeenCalled();
|
||||||
|
expect(props.buffer.backspace).toHaveBeenCalled();
|
||||||
|
expect(props.buffer.newline).toHaveBeenCalled();
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -329,7 +329,15 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||||
|
|
||||||
if (key.name === 'return' && !key.ctrl && !key.meta && !key.paste) {
|
if (key.name === 'return' && !key.ctrl && !key.meta && !key.paste) {
|
||||||
if (buffer.text.trim()) {
|
if (buffer.text.trim()) {
|
||||||
handleSubmitAndClear(buffer.text);
|
const [row, col] = buffer.cursor;
|
||||||
|
const line = buffer.lines[row];
|
||||||
|
const charBefore = col > 0 ? cpSlice(line, col - 1, col) : '';
|
||||||
|
if (charBefore === '\\') {
|
||||||
|
buffer.backspace();
|
||||||
|
buffer.newline();
|
||||||
|
} else {
|
||||||
|
handleSubmitAndClear(buffer.text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue