Skip to content

Commit c79072c

Browse files
committed
Move collapse-related code out of cellRenderer to a cell part #131808
1 parent e2d1be5 commit c79072c

File tree

7 files changed

+161
-112
lines changed

7 files changed

+161
-112
lines changed

src/vs/workbench/contrib/notebook/browser/view/cellParts/cellExecution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { BaseCellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/vi
1212
import { NotebookCellInternalMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
1313

1414
export class CellExecutionPart extends CellPart {
15-
private kernelDisposables = new DisposableStore();
15+
private kernelDisposables = this._register(new DisposableStore());
1616
private currentCell: ICellViewModel | undefined;
1717

1818
constructor(

src/vs/workbench/contrib/notebook/browser/view/cellParts/cellFocusIndicator.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as DOM from 'vs/base/browser/dom';
77
import { FastDomNode } from 'vs/base/browser/fastDomNode';
88
import { DisposableStore } from 'vs/base/common/lifecycle';
9-
import { ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
9+
import { CodeCellLayoutInfo, ICellViewModel, INotebookEditorDelegate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
1010
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
1111
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellPart';
1212
import { CellTitleToolbarPart } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellToolbars';
@@ -55,6 +55,19 @@ export class CellFocusIndicator extends CellPart {
5555
this.currentElement.isOutputCollapsed = !this.currentElement.isOutputCollapsed;
5656
}
5757
}));
58+
59+
this._register(DOM.addDisposableListener(this.left.domNode, DOM.EventType.DBLCLICK, e => {
60+
if (!this.currentElement || !this.notebookEditor.hasModel()) {
61+
return;
62+
}
63+
64+
const clickedOnInput = e.offsetY < (this.currentElement.layoutInfo as CodeCellLayoutInfo).outputContainerOffset;
65+
if (clickedOnInput) {
66+
this.currentElement.isInputCollapsed = !this.currentElement.isInputCollapsed;
67+
} else {
68+
this.currentElement.isOutputCollapsed = !this.currentElement.isOutputCollapsed;
69+
}
70+
}));
5871
}
5972

6073
renderCell(element: ICellViewModel, templateData: BaseCellRenderTemplate): void {

src/vs/workbench/contrib/notebook/browser/view/cellParts/codeCell.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewMod
3030
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
3131
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
3232

33-
3433
export class CodeCell extends Disposable {
3534
private _outputContainerRenderer: CellOutputContainer;
3635

@@ -521,7 +520,6 @@ export class CodeCell extends Disposable {
521520
this.viewCell.detachTextEditor();
522521
this._removeInputCollapsePreview();
523522
this._outputContainerRenderer.dispose();
524-
this.templateData.focusIndicator.left.setHeight(0);
525523
this._pendingLayout?.dispose();
526524

527525
super.dispose();
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as DOM from 'vs/base/browser/dom';
7+
import { ICellViewModel, INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
8+
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
9+
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellPart';
10+
import { BaseCellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon';
11+
12+
export class CollapsedCellInput extends CellPart {
13+
private currentCell: ICellViewModel | undefined;
14+
15+
constructor(
16+
private readonly notebookEditor: INotebookEditor,
17+
cellInputCollapsedContainer: HTMLElement,
18+
) {
19+
super();
20+
21+
this._register(DOM.addDisposableListener(cellInputCollapsedContainer, DOM.EventType.DBLCLICK, e => {
22+
if (!this.currentCell || !this.notebookEditor.hasModel()) {
23+
return;
24+
}
25+
26+
if (this.currentCell.isInputCollapsed) {
27+
this.currentCell.isInputCollapsed = false;
28+
} else {
29+
this.currentCell.isOutputCollapsed = false;
30+
}
31+
}));
32+
33+
this._register(DOM.addDisposableListener(cellInputCollapsedContainer, DOM.EventType.CLICK, e => {
34+
if (!this.currentCell || !this.notebookEditor.hasModel()) {
35+
return;
36+
}
37+
38+
const element = e.target as HTMLElement;
39+
40+
if (element && element.classList && element.classList.contains('expandInputIcon')) {
41+
// clicked on the expand icon
42+
this.currentCell.isInputCollapsed = false;
43+
}
44+
}));
45+
}
46+
47+
renderCell(element: ICellViewModel, templateData: BaseCellRenderTemplate): void {
48+
this.currentCell = element;
49+
}
50+
51+
prepareLayout(): void {
52+
}
53+
54+
updateInternalLayoutNow(element: ICellViewModel): void {
55+
}
56+
57+
updateState(element: ICellViewModel, e: CellViewModelStateChangeEvent): void {
58+
}
59+
}
60+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as DOM from 'vs/base/browser/dom';
7+
import { Codicon, CSSIcon } from 'vs/base/common/codicons';
8+
import { localize } from 'vs/nls';
9+
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
10+
import { EXPAND_CELL_OUTPUT_COMMAND_ID, ICellViewModel, INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
11+
import { CellViewModelStateChangeEvent } from 'vs/workbench/contrib/notebook/browser/notebookViewEvents';
12+
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellPart';
13+
import { BaseCellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon';
14+
15+
const $ = DOM.$;
16+
17+
export class CollapsedCellOutput extends CellPart {
18+
private currentCell: ICellViewModel | undefined;
19+
20+
constructor(
21+
private readonly notebookEditor: INotebookEditor,
22+
cellOutputCollapseContainer: HTMLElement,
23+
@IKeybindingService keybindingService: IKeybindingService
24+
) {
25+
super();
26+
27+
const placeholder = DOM.append(cellOutputCollapseContainer, $('span.expandOutputPlaceholder')) as HTMLElement;
28+
placeholder.textContent = localize('cellOutputsCollapsedMsg', "Outputs are collapsed");
29+
const expandIcon = DOM.append(cellOutputCollapseContainer, $('span.expandOutputIcon'));
30+
expandIcon.classList.add(...CSSIcon.asClassNameArray(Codicon.more));
31+
32+
const keybinding = keybindingService.lookupKeybinding(EXPAND_CELL_OUTPUT_COMMAND_ID);
33+
if (keybinding) {
34+
placeholder.title = localize('cellExpandOutputButtonLabelWithDoubleClick', "Double click to expand cell output ({0})", keybinding.getLabel());
35+
cellOutputCollapseContainer.title = localize('cellExpandOutputButtonLabel', "Expand Cell Output (${0})", keybinding.getLabel());
36+
}
37+
38+
DOM.hide(cellOutputCollapseContainer);
39+
40+
this._register(DOM.addDisposableListener(expandIcon, DOM.EventType.CLICK, () => this.expand()));
41+
this._register(DOM.addDisposableListener(cellOutputCollapseContainer, DOM.EventType.DBLCLICK, () => this.expand()));
42+
}
43+
44+
private expand() {
45+
if (!this.currentCell) {
46+
return;
47+
}
48+
49+
if (!this.currentCell) {
50+
return;
51+
}
52+
53+
const textModel = this.notebookEditor.textModel!;
54+
const index = textModel.cells.indexOf(this.currentCell.model);
55+
56+
if (index < 0) {
57+
return;
58+
}
59+
60+
this.currentCell.isOutputCollapsed = !this.currentCell.isOutputCollapsed;
61+
}
62+
63+
renderCell(element: ICellViewModel, templateData: BaseCellRenderTemplate): void {
64+
this.currentCell = element;
65+
}
66+
67+
prepareLayout(): void {
68+
}
69+
70+
updateInternalLayoutNow(element: ICellViewModel): void {
71+
}
72+
73+
updateState(element: ICellViewModel, e: CellViewModelStateChangeEvent): void {
74+
}
75+
}

src/vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ import { Range } from 'vs/editor/common/core/range';
1515
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1616
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1717
import { ICellOutputViewModel, ICellViewModel } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
18-
import { CellFocusIndicator } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellFocusIndicator';
1918
import { CellPart } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellPart';
2019
import { CellEditorStatusBar } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellStatusPart';
21-
import { FoldedCellHint } from 'vs/workbench/contrib/notebook/browser/view/cellParts/foldedCellHint';
2220
import { CellViewModel, NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl';
2321
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
2422

@@ -101,7 +99,6 @@ export interface BaseCellRenderTemplate {
10199
container: HTMLElement;
102100
cellContainer: HTMLElement;
103101
decorationContainer: HTMLElement;
104-
focusIndicator: CellFocusIndicator;
105102
readonly templateDisposables: DisposableStore;
106103
readonly elementDisposables: DisposableStore;
107104
currentRenderedCell?: ICellViewModel;
@@ -113,7 +110,6 @@ export interface BaseCellRenderTemplate {
113110
export interface MarkdownCellRenderTemplate extends BaseCellRenderTemplate {
114111
editorContainer: HTMLElement;
115112
foldingIndicator: HTMLElement;
116-
foldedCellHint: FoldedCellHint;
117113
currentEditor?: ICodeEditor;
118114
}
119115

0 commit comments

Comments
 (0)