Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add context menu toggle + command pallette toggle sticky #188552

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
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);
Loading