Skip to content

Commit 89eec20

Browse files
authored
Merge pull request microsoft#180715 from microsoft/aamunger/scrollOutputWithKeys
keep scroll related key events in scrollable region
2 parents a34b228 + 9742545 commit 89eec20

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

extensions/notebook-renderers/src/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,28 @@ function onScrollHandler(e: globalThis.Event) {
198198
}
199199
}
200200

201+
function onKeypressHandler(e: KeyboardEvent) {
202+
if (e.ctrlKey || e.shiftKey) {
203+
return;
204+
}
205+
if (e.code === 'ArrowDown' || e.code === 'End' || e.code === 'ArrowUp' || e.code === 'Home') {
206+
// These should change the scroll position, not adjust the selected cell in the notebook
207+
e.stopPropagation();
208+
}
209+
}
210+
201211
// if there is a scrollable output, it will be scrolled to the given value if provided or the bottom of the element
202212
function initializeScroll(scrollableElement: HTMLElement, disposables: DisposableStore, scrollTop?: number) {
203213
if (scrollableElement.classList.contains(scrollableClass)) {
204-
scrollableElement.classList.toggle('scrollbar-visible', scrollableElement.scrollHeight > scrollableElement.clientHeight);
214+
const scrollbarVisible = scrollableElement.scrollHeight > scrollableElement.clientHeight;
215+
scrollableElement.classList.toggle('scrollbar-visible', scrollbarVisible);
205216
scrollableElement.scrollTop = scrollTop !== undefined ? scrollTop : scrollableElement.scrollHeight;
206-
scrollableElement.addEventListener('scroll', onScrollHandler);
207-
disposables.push({ dispose: () => scrollableElement.removeEventListener('scroll', onScrollHandler) });
217+
if (scrollbarVisible) {
218+
scrollableElement.addEventListener('scroll', onScrollHandler);
219+
disposables.push({ dispose: () => scrollableElement.removeEventListener('scroll', onScrollHandler) });
220+
scrollableElement.addEventListener('keydown', onKeypressHandler);
221+
disposables.push({ dispose: () => scrollableElement.removeEventListener('keydown', onKeypressHandler) });
222+
}
208223
}
209224
}
210225

src/vs/workbench/contrib/notebook/browser/controller/editActions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis
1919
import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';
2020
import { changeCellToKind, runDeleteAction } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations';
2121
import { CellToolbarOrder, CELL_TITLE_CELL_GROUP_ID, CELL_TITLE_OUTPUT_GROUP_ID, executeNotebookCondition, INotebookActionContext, INotebookCellActionContext, NotebookAction, NotebookCellAction, NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
22-
import { NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
22+
import { NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_HAS_OUTPUTS, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, NOTEBOOK_CELL_TYPE, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_OUTPUT_FOCUSED, NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
2323
import { CellEditState, CHANGE_CELL_LANGUAGE, DETECT_CELL_LANGUAGE, QUIT_EDIT_CELL_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
2424
import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons';
2525
import { CellEditType, CellKind, ICellEditOperation, NotebookCellExecutionState, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
@@ -103,6 +103,12 @@ registerAction2(class QuitEditCellAction extends NotebookCellAction {
103103
primary: KeyCode.Escape,
104104
weight: NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT - 5
105105
},
106+
{
107+
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED,
108+
NOTEBOOK_OUTPUT_FOCUSED),
109+
primary: KeyCode.Escape,
110+
weight: KeybindingWeight.WorkbenchContrib + 5
111+
},
106112
{
107113
when: ContextKeyExpr.and(
108114
quitEditCondition,

0 commit comments

Comments
 (0)