Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion src/vs/workbench/browser/parts/editor/breadcrumbsControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,8 @@ registerAction2(class ToggleBreadcrumb extends Action2 {
{ id: MenuId.CommandPalette },
{ id: MenuId.MenubarAppearanceMenu, group: '4_editor', order: 2 },
{ id: MenuId.NotebookToolbar, group: 'notebookLayout', order: 2 },
{ id: MenuId.StickyScrollContext }
{ id: MenuId.StickyScrollContext },
{ id: MenuId.NotebookStickyScrollContext, group: 'notebookView', order: 2 }
]
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ export class ToggleNotebookStickyScroll extends Action2 {
id: 'notebook.action.toggleNotebookStickyScroll',
title: {
...localize2('toggleStickyScroll', "Toggle Notebook Sticky Scroll"),
mnemonicTitle: localize({ key: 'mitoggleStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Toggle Notebook Sticky Scroll"),
mnemonicTitle: localize({ key: 'mitoggleNotebookStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&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"),
mnemonicTitle: localize({ key: 'mitoggleNotebookStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Toggle Notebook Sticky Scroll"),
},
menu: [
{ id: MenuId.CommandPalette },
{ id: MenuId.NotebookStickyScrollContext }
{
id: MenuId.NotebookStickyScrollContext,
group: 'notebookView',
order: 2
}
]
});
}
Expand All @@ -56,6 +60,51 @@ export class ToggleNotebookStickyScroll extends Action2 {
}
}

type RunInSectionContext = {
target: HTMLElement;
currentStickyLines: Map<OutlineEntry, { line: NotebookStickyLine; rendered: boolean }>;
notebookEditor: INotebookEditor;
};

export class RunInSectionStickyScroll extends Action2 {
constructor() {
super({
id: 'notebook.action.runInSection',
title: {
...localize2('runInSectionStickyScroll', "Run Section"),
mnemonicTitle: localize({ key: 'mirunInSectionStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Run Section"),
},
menu: [
{
id: MenuId.NotebookStickyScrollContext,
group: 'notebookExecution',
order: 1
}
]
});
}

override async run(accessor: ServicesAccessor, context: RunInSectionContext, ...args: any[]): Promise<void> {
const selectedElement = context.target.parentElement;
const stickyLines: Map<OutlineEntry, {
line: NotebookStickyLine;
rendered: boolean;
}> = context.currentStickyLines;

const selectedOutlineEntry = Array.from(stickyLines.values()).find(entry => entry.line.element.contains(selectedElement))?.line.entry;
if (!selectedOutlineEntry) {
return;
}

const flatList: OutlineEntry[] = [];
selectedOutlineEntry.asFlatList(flatList);

const cellViewModels = flatList.map(entry => entry.cell);
const notebookEditor: INotebookEditor = context.notebookEditor;
notebookEditor.executeNotebookCells(cellViewModels);
}
}

export class NotebookStickyLine extends Disposable {
constructor(
public readonly element: HTMLElement,
Expand All @@ -78,14 +127,6 @@ export class NotebookStickyLine extends Disposable {
}
}));

// folding icon hovers
// this._register(DOM.addDisposableListener(this.element, DOM.EventType.MOUSE_OVER, () => {
// this.foldingIcon.setVisible(true);
// }));
// this._register(DOM.addDisposableListener(this.element, DOM.EventType.MOUSE_OUT, () => {
// this.foldingIcon.setVisible(false);
// }));

}

private toggleFoldRange(currentState: CellFoldingState) {
Expand Down Expand Up @@ -145,7 +186,6 @@ export class NotebookStickyScroll extends Disposable {
private readonly _onDidChangeNotebookStickyScroll = this._register(new Emitter<number>());
readonly onDidChangeNotebookStickyScroll: Event<number> = this._onDidChangeNotebookStickyScroll.event;


getDomNode(): HTMLElement {
return this.domNode;
}
Expand Down Expand Up @@ -205,9 +245,17 @@ export class NotebookStickyScroll extends Disposable {

private onContextMenu(e: MouseEvent) {
const event = new StandardMouseEvent(DOM.getWindow(this.domNode), e);

const context: RunInSectionContext = {
target: event.target,
currentStickyLines: this.currentStickyLines,
notebookEditor: this.notebookEditor,
};

this._contextMenuService.showContextMenu({
menuId: MenuId.NotebookStickyScrollContext,
getAnchor: () => event,
menuActionOptions: { shouldForwardArgs: true, arg: context },
});
}

Expand Down Expand Up @@ -384,6 +432,7 @@ export class NotebookStickyScroll extends Disposable {
stickyHeader.innerText = entry.label;

stickyElement.append(stickyFoldingIcon.domNode, stickyHeader);

return new NotebookStickyLine(stickyElement, stickyFoldingIcon, stickyHeader, entry, notebookEditor);
}

Expand All @@ -395,6 +444,7 @@ export class NotebookStickyScroll extends Disposable {

override dispose() {
this._disposables.dispose();
// this._actionRunnerDisposables.dispose();
this.disposeCurrentStickyLines();
this.notebookOutline.dispose();
super.dispose();
Expand Down Expand Up @@ -490,3 +540,4 @@ export function computeContent(notebookEditor: INotebookEditor, notebookCellList
}

registerAction2(ToggleNotebookStickyScroll);
registerAction2(RunInSectionStickyScroll);