Skip to content

Commit d816dc5

Browse files
authored
Fix shift tab to work again (#11652)
1 parent c1d8619 commit d816dc5

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

news/2 Fixes/11495.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make shift+tab work again in the interactive window. Escaping focus from the prompt is now relegated to 'Shift+Esc'.

src/datascience-ui/history-react/interactiveCell.tsx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export class InteractiveCell extends React.Component<IInteractiveCellProps> {
142142
ref={this.wrapperRef}
143143
tabIndex={0}
144144
onKeyDown={this.onKeyDown}
145+
onKeyUp={this.onKeyUp}
145146
onClick={this.onMouseClick}
146147
>
147148
<div className={cellOuterClass}>
@@ -354,24 +355,47 @@ export class InteractiveCell extends React.Component<IInteractiveCellProps> {
354355
}
355356
};
356357

358+
private onKeyUp = (event: React.KeyboardEvent<HTMLDivElement>) => {
359+
// Handle keydown events for the entire cell
360+
if (this.getCell().id === Identifiers.EditCellId) {
361+
const e: IKeyboardEvent = {
362+
code: event.key,
363+
shiftKey: event.shiftKey,
364+
ctrlKey: event.ctrlKey,
365+
metaKey: event.metaKey,
366+
altKey: event.altKey,
367+
target: event.target as HTMLDivElement,
368+
stopPropagation: () => event.stopPropagation(),
369+
preventDefault: () => event.preventDefault()
370+
};
371+
this.onEditCellKeyUp(Identifiers.EditCellId, e);
372+
}
373+
};
374+
357375
private onEditCellKeyDown = (_cellId: string, e: IKeyboardEvent) => {
358-
if (e.code === 'Tab' && e.shiftKey) {
359-
this.editCellShiftTab(e);
360-
} else if (e.code === 'Enter' && e.shiftKey) {
376+
if (e.code === 'Enter' && e.shiftKey) {
361377
this.editCellSubmit(e);
362378
} else if (e.code === 'NumpadEnter' && e.shiftKey) {
363379
this.editCellSubmit(e);
364380
} else if (e.code === 'KeyU' && e.ctrlKey && e.editorInfo && !e.editorInfo.isSuggesting) {
365381
e.editorInfo.clear();
366382
e.stopPropagation();
367383
e.preventDefault();
368-
} else if (e.code === 'Escape' && e.editorInfo && !e.editorInfo.isSuggesting) {
384+
} else if (e.code === 'Escape' && !e.shiftKey && e.editorInfo && !e.editorInfo.isSuggesting) {
369385
e.editorInfo.clear();
370386
e.stopPropagation();
371387
e.preventDefault();
372388
}
373389
};
374390

391+
private onEditCellKeyUp = (_cellId: string, e: IKeyboardEvent) => {
392+
// Special case. Escape + Shift only comes as a key up because shift comes as the
393+
// key down.
394+
if (e.code === 'Escape' && e.shiftKey) {
395+
this.editCellShiftEscape(e);
396+
}
397+
};
398+
375399
private editCellSubmit(e: IKeyboardEvent) {
376400
if (e.editorInfo && e.editorInfo.contents) {
377401
// Prevent shift+enter from turning into a enter
@@ -409,9 +433,9 @@ export class InteractiveCell extends React.Component<IInteractiveCellProps> {
409433
}
410434
}
411435

412-
private editCellShiftTab = (e: IKeyboardEvent) => {
436+
private editCellShiftEscape = (e: IKeyboardEvent) => {
413437
const focusedElement = document.activeElement;
414-
if (focusedElement !== null && e.editorInfo && !e.editorInfo.isSuggesting) {
438+
if (focusedElement !== null) {
415439
const nextTabStop = this.findTabStop(1, focusedElement);
416440
if (nextTabStop) {
417441
e.stopPropagation();

0 commit comments

Comments
 (0)