Skip to content

Commit e15c125

Browse files
authored
fix: DH-14237: down arrow in console not returning to blank field (#1082)
Fixes DH-14237 Was incorrectly converted in #646 Switched the arrow keys to use `code` instead of `keyCode` because RTL user-event does not set `keyCode` which is a deprecated property
1 parent 447421f commit e15c125

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

packages/console/src/Console.test.tsx

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import dh from '@deephaven/jsapi-shim';
3-
import { render } from '@testing-library/react';
3+
import { render, screen } from '@testing-library/react';
4+
import userEvent from '@testing-library/user-event';
45
import { Console } from './Console';
56
import { CommandHistoryStorage } from './command-history';
67

@@ -30,12 +31,13 @@ jest.mock('./Console', () => ({
3031
commandHistory: jest.fn(),
3132
}));
3233

33-
function makeConsoleWrapper() {
34+
function makeConsoleWrapper(consoleRef = React.createRef<Console>()) {
3435
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3536
const session = new (dh as any).IdeSession('test');
3637
const commandHistoryStorage = makeMockCommandHistoryStorage();
3738
return render(
3839
<Console
40+
ref={consoleRef}
3941
commandHistoryStorage={commandHistoryStorage}
4042
focusCommandHistory={() => undefined}
4143
openObject={() => undefined}
@@ -49,3 +51,19 @@ function makeConsoleWrapper() {
4951
it('renders without crashing', () => {
5052
makeConsoleWrapper();
5153
});
54+
55+
it('Handles arrow to prev item and back to blank', async () => {
56+
const user = userEvent.setup();
57+
const consoleRef = React.createRef<Console>();
58+
makeConsoleWrapper(consoleRef);
59+
60+
const consoleInput = consoleRef.current?.consoleInput.current;
61+
consoleInput!.history = ['A']; // monaco splits the text into separate tags if this is multiple characters
62+
63+
consoleInput?.focus();
64+
await user.keyboard('[ArrowUp]');
65+
expect(screen.queryByText('A')).toBeInTheDocument();
66+
67+
await user.keyboard('[ArrowDown]');
68+
expect(screen.queryByText('A')).not.toBeInTheDocument();
69+
});

packages/console/src/ConsoleInput.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class ConsoleInput extends PureComponent<
218218
const { lineNumber } = position;
219219
const model = commandEditor?.getModel();
220220
if (
221-
keyEvent.keyCode === monaco.KeyCode.UpArrow &&
221+
keyEvent.code === 'ArrowUp' &&
222222
!this.isSuggestionMenuPopulated() &&
223223
lineNumber === 1
224224
) {
@@ -236,7 +236,7 @@ export class ConsoleInput extends PureComponent<
236236
}
237237

238238
if (
239-
keyEvent.keyCode === monaco.KeyCode.DownArrow &&
239+
keyEvent.code === 'ArrowDown' &&
240240
!this.isSuggestionMenuPopulated() &&
241241
lineNumber === model?.getLineCount()
242242
) {
@@ -380,7 +380,7 @@ export class ConsoleInput extends PureComponent<
380380
* @param index The index to load. Null to load command started in the editor and not in the history
381381
*/
382382
loadCommand(index: number | null): void {
383-
if (index === null || index >= this.history.length) {
383+
if (index !== null && index >= this.history.length) {
384384
return;
385385
}
386386

0 commit comments

Comments
 (0)