Skip to content

Commit 5e0c49c

Browse files
authored
Merge pull request microsoft#188552 from microsoft/willowy-stingray
add context menu toggle + command pallette toggle sticky
2 parents a5fa6ad + 176dfca commit 5e0c49c

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/vs/platform/actions/common/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export class MenuId {
145145
static readonly InteractiveCellExecute = new MenuId('InteractiveCellExecute');
146146
static readonly InteractiveInputExecute = new MenuId('InteractiveInputExecute');
147147
static readonly NotebookToolbar = new MenuId('NotebookToolbar');
148+
static readonly NotebookStickyScrollContext = new MenuId('NotebookStickyScrollContext');
148149
static readonly NotebookCellTitle = new MenuId('NotebookCellTitle');
149150
static readonly NotebookCellDelete = new MenuId('NotebookCellDelete');
150151
static readonly NotebookCellInsert = new MenuId('NotebookCellInsert');

src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorStickyScroll.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,50 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { localize } from 'vs/nls';
67
import * as DOM from 'vs/base/browser/dom';
78
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
9+
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
10+
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
11+
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
12+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
13+
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
14+
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
815
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
916
import { INotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon';
1017
import { NotebookCellOutlineProvider, OutlineEntry } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineProvider';
1118
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
1219

20+
export class ToggleNotebookStickyScroll extends Action2 {
21+
22+
constructor() {
23+
super({
24+
id: 'notebook.action.toggleNotebookStickyScroll',
25+
title: {
26+
value: localize('toggleStickyScroll', "Toggle Notebook Sticky Scroll"),
27+
mnemonicTitle: localize({ key: 'mitoggleStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Toggle Notebook Sticky Scroll"),
28+
original: 'Toggle Notebook Sticky Scroll',
29+
},
30+
category: Categories.View,
31+
toggled: {
32+
condition: ContextKeyExpr.equals('config.notebook.stickyScroll.enabled', true),
33+
title: localize('notebookStickyScroll', "Notebook Sticky Scroll"),
34+
mnemonicTitle: localize({ key: 'miNotebookStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Notebook Sticky Scroll"),
35+
},
36+
menu: [
37+
{ id: MenuId.CommandPalette },
38+
{ id: MenuId.NotebookStickyScrollContext }
39+
]
40+
});
41+
}
42+
43+
override async run(accessor: ServicesAccessor): Promise<void> {
44+
const configurationService = accessor.get(IConfigurationService);
45+
const newValue = !configurationService.getValue('notebook.stickyScroll.enabled');
46+
return configurationService.updateValue('notebook.stickyScroll.enabled', newValue);
47+
}
48+
}
49+
1350
class NotebookStickyLine extends Disposable {
1451
constructor(
1552
public readonly element: HTMLElement,
@@ -56,11 +93,11 @@ export class NotebookStickyScroll extends Disposable {
5693
private readonly domNode: HTMLElement,
5794
private readonly notebookEditor: INotebookEditor,
5895
private readonly notebookOutline: NotebookCellOutlineProvider,
59-
private readonly notebookCellList: INotebookCellList
96+
private readonly notebookCellList: INotebookCellList,
97+
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
6098
) {
6199
super();
62100

63-
64101
if (this.notebookEditor.notebookOptions.getLayoutConfiguration().stickyScroll) {
65102
this.init();
66103
}
@@ -73,6 +110,17 @@ export class NotebookStickyScroll extends Disposable {
73110
this.setTop();
74111
}
75112
}));
113+
114+
this._register(DOM.addDisposableListener(this.domNode, DOM.EventType.CONTEXT_MENU, async (event: MouseEvent) => {
115+
this.onContextMenu(event);
116+
}));
117+
}
118+
119+
private onContextMenu(event: MouseEvent) {
120+
this._contextMenuService.showContextMenu({
121+
menuId: MenuId.NotebookStickyScrollContext,
122+
getAnchor: () => event,
123+
});
76124
}
77125

78126
private updateConfig() {
@@ -388,3 +436,5 @@ export class NotebookStickyScroll extends Disposable {
388436
super.dispose();
389437
}
390438
}
439+
440+
registerAction2(ToggleNotebookStickyScroll);

0 commit comments

Comments
 (0)