Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -629,7 +629,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 @@ -246,6 +246,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
return this._notebookViewModel?.notebookDocument;
}

get notebookStickyScroll(): NotebookStickyScroll {
return this._notebookStickyScroll;
}

get isReadOnly() {
return this._notebookViewModel?.options.isReadOnly ?? false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { foldingCollapsedIcon, foldingExpandedIcon } from 'vs/editor/contrib/fol
import { MarkupCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markupCellViewModel';
import { FoldingController } from 'vs/workbench/contrib/notebook/browser/controller/foldingController';
import { NotebookOptionsChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookOptions';
import { IRunEvent } from 'vs/base/common/actions';
import { ICommandService } from 'vs/platform/commands/common/commands';

export class ToggleNotebookStickyScroll extends Action2 {

Expand All @@ -44,7 +46,11 @@ export class ToggleNotebookStickyScroll extends Action2 {
},
menu: [
{ id: MenuId.CommandPalette },
{ id: MenuId.NotebookStickyScrollContext }
{
id: MenuId.NotebookStickyScrollContext,
group: 'notebookView',
order: 2
}
]
});
}
Expand All @@ -56,6 +62,45 @@ export class ToggleNotebookStickyScroll extends Action2 {
}
}

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, ...args: any[]): Promise<void> {
const selectedElement: HTMLElement = args[0].parentElement;
const stickyLines: Map<OutlineEntry, {
line: NotebookStickyLine;
rendered: boolean;
}> = args[1];

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 = args[2];
notebookEditor.executeNotebookCells(cellViewModels);
}
}

export class NotebookStickyLine extends Disposable {
constructor(
public readonly element: HTMLElement,
Expand All @@ -78,14 +123,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 +182,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 @@ -185,6 +221,7 @@ export class NotebookStickyScroll extends Disposable {
private readonly notebookOutline: NotebookCellOutlineProvider,
private readonly notebookCellList: INotebookCellList,
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
@ICommandService private readonly commandService: ICommandService
) {
super();

Expand All @@ -208,6 +245,18 @@ export class NotebookStickyScroll extends Disposable {
this._contextMenuService.showContextMenu({
menuId: MenuId.NotebookStickyScrollContext,
getAnchor: () => event,
actionRunner: {
run: async (action) => {
if (action.id === 'notebook.action.runInSection') {
this.commandService.executeCommand(action.id, event.target, this.currentStickyLines, this.notebookEditor);
} else {
this.commandService.executeCommand(action.id);
}
},
onDidRun: new Emitter<IRunEvent>().event,
onWillRun: new Emitter<IRunEvent>().event,
dispose: () => { }
},
});
}

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

stickyElement.append(stickyFoldingIcon.domNode, stickyHeader);

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

Expand Down Expand Up @@ -490,3 +540,4 @@ export function computeContent(notebookEditor: INotebookEditor, notebookCellList
}

registerAction2(ToggleNotebookStickyScroll);
registerAction2(RunInSectionStickyScroll);
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,9 @@ export function isCompositeNotebookEditorInput(thing: unknown): thing is ICompos
&& Array.isArray((<ICompositeNotebookEditorInput>thing).editorInputs)
&& ((<ICompositeNotebookEditorInput>thing).editorInputs.every(input => input instanceof NotebookEditorInput));
}

export function isNotebookEditorInput(thing: unknown): thing is NotebookEditorInput {
return !!thing
&& typeof thing === 'object'
&& thing instanceof NotebookEditorInput;
}