Skip to content

Commit

Permalink
Merge pull request #188552 from microsoft/willowy-stingray
Browse files Browse the repository at this point in the history
add context menu toggle + command pallette toggle sticky
  • Loading branch information
rebornix authored Jul 22, 2023
2 parents a5fa6ad + 176dfca commit 5e0c49c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class MenuId {
static readonly InteractiveCellExecute = new MenuId('InteractiveCellExecute');
static readonly InteractiveInputExecute = new MenuId('InteractiveInputExecute');
static readonly NotebookToolbar = new MenuId('NotebookToolbar');
static readonly NotebookStickyScrollContext = new MenuId('NotebookStickyScrollContext');

This comment has been minimized.

Copy link
@Torie2

Torie2 Jul 22, 2023

Ok

static readonly NotebookCellTitle = new MenuId('NotebookCellTitle');
static readonly NotebookCellDelete = new MenuId('NotebookCellDelete');
static readonly NotebookCellInsert = new MenuId('NotebookCellInsert');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,50 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { localize } from 'vs/nls';
import * as DOM from 'vs/base/browser/dom';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon';
import { NotebookCellOutlineProvider, OutlineEntry } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineProvider';
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';

export class ToggleNotebookStickyScroll extends Action2 {

constructor() {
super({
id: 'notebook.action.toggleNotebookStickyScroll',
title: {
value: localize('toggleStickyScroll', "Toggle Notebook Sticky Scroll"),
mnemonicTitle: localize({ key: 'mitoggleStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Toggle Notebook Sticky Scroll"),
original: 'Toggle Notebook Sticky Scroll',
},
category: Categories.View,
toggled: {
condition: ContextKeyExpr.equals('config.notebook.stickyScroll.enabled', true),
title: localize('notebookStickyScroll', "Notebook Sticky Scroll"),
mnemonicTitle: localize({ key: 'miNotebookStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Notebook Sticky Scroll"),
},
menu: [
{ id: MenuId.CommandPalette },
{ id: MenuId.NotebookStickyScrollContext }
]
});
}

override async run(accessor: ServicesAccessor): Promise<void> {
const configurationService = accessor.get(IConfigurationService);
const newValue = !configurationService.getValue('notebook.stickyScroll.enabled');
return configurationService.updateValue('notebook.stickyScroll.enabled', newValue);
}
}

class NotebookStickyLine extends Disposable {
constructor(
public readonly element: HTMLElement,
Expand Down Expand Up @@ -56,11 +93,11 @@ export class NotebookStickyScroll extends Disposable {
private readonly domNode: HTMLElement,
private readonly notebookEditor: INotebookEditor,
private readonly notebookOutline: NotebookCellOutlineProvider,
private readonly notebookCellList: INotebookCellList
private readonly notebookCellList: INotebookCellList,
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
) {
super();


if (this.notebookEditor.notebookOptions.getLayoutConfiguration().stickyScroll) {
this.init();
}
Expand All @@ -73,6 +110,17 @@ export class NotebookStickyScroll extends Disposable {
this.setTop();
}
}));

this._register(DOM.addDisposableListener(this.domNode, DOM.EventType.CONTEXT_MENU, async (event: MouseEvent) => {
this.onContextMenu(event);
}));
}

private onContextMenu(event: MouseEvent) {
this._contextMenuService.showContextMenu({
menuId: MenuId.NotebookStickyScrollContext,
getAnchor: () => event,
});
}

private updateConfig() {
Expand Down Expand Up @@ -388,3 +436,5 @@ export class NotebookStickyScroll extends Disposable {
super.dispose();
}
}

registerAction2(ToggleNotebookStickyScroll);

0 comments on commit 5e0c49c

Please sign in to comment.