Skip to content

Commit b08a404

Browse files
committed
support editing of cell content
1 parent b414733 commit b08a404

3 files changed

Lines changed: 10 additions & 94 deletions

File tree

src/vs/workbench/contrib/notebook/browser/diff/cellComponents.ts

Lines changed: 7 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const fixedDiffEditorOptions: IDiffEditorOptions = {
5353
glyphMargin: true,
5454
enableSplitViewResizing: false,
5555
renderIndicators: false,
56+
readOnly: false
5657
};
5758

5859

@@ -355,8 +356,8 @@ abstract class AbstractCellRenderer extends Disposable {
355356
if (originalMetadataSource !== modifiedMetadataSource) {
356357
this._metadataEditor = this.instantiationService.createInstance(DiffEditorWidget, this._metadataEditorContainer!, {
357358
...fixedDiffEditorOptions,
358-
overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode()
359-
359+
overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(),
360+
readOnly: true
360361
});
361362

362363
DOM.addClass(this._metadataEditorContainer!, 'diff');
@@ -427,7 +428,8 @@ abstract class AbstractCellRenderer extends Disposable {
427428
if (originalOutputsSource !== modifiedOutputsSource) {
428429
this._outputEditor = this.instantiationService.createInstance(DiffEditorWidget, this._outputEditorContainer!, {
429430
...fixedDiffEditorOptions,
430-
overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode()
431+
overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(),
432+
readOnly: true
431433
});
432434

433435
DOM.addClass(this._outputEditorContainer!, 'diff');
@@ -504,93 +506,6 @@ abstract class AbstractCellRenderer extends Disposable {
504506
abstract layout(state: { outerWidth?: boolean, editorHeight?: boolean, metadataEditor?: boolean, outputEditor?: boolean }): void;
505507
}
506508

507-
export class UnchangedCell extends AbstractCellRenderer {
508-
private _editor!: CodeEditorWidget;
509-
510-
constructor(
511-
readonly notebookEditor: INotebookTextDiffEditor,
512-
readonly cell: CellDiffViewModel,
513-
readonly templateData: CellDiffRenderTemplate,
514-
@IModeService readonly modeService: IModeService,
515-
@IModelService protected modelService: IModelService,
516-
@IInstantiationService protected readonly instantiationService: IInstantiationService,
517-
) {
518-
super(notebookEditor, cell, templateData, 'full', instantiationService, modeService, modelService);
519-
}
520-
521-
initData() {
522-
}
523-
524-
styleContainer(container: HTMLElement) {
525-
}
526-
527-
buildSourceEditor(sourceContainer: HTMLElement) {
528-
const editorContainer = DOM.append(sourceContainer, DOM.$('.editor-container'));
529-
const originalCell = this.cell.original!;
530-
const lineCount = originalCell.textBuffer.getLineCount();
531-
const lineHeight = this.notebookEditor.getLayoutInfo().fontInfo.lineHeight || 17;
532-
const editorHeight = lineCount * lineHeight + EDITOR_TOP_PADDING + EDITOR_BOTTOM_PADDING;
533-
534-
this._editor = this.instantiationService.createInstance(CodeEditorWidget, editorContainer, {
535-
...fixedEditorOptions,
536-
dimension: {
537-
width: this.notebookEditor.getLayoutInfo().width - 2 * DIFF_CELL_MARGIN,
538-
height: editorHeight
539-
},
540-
overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode()
541-
}, {});
542-
543-
this._register(this._editor.onDidContentSizeChange((e) => {
544-
if (e.contentHeightChanged) {
545-
this._layoutInfo.editorHeight = e.contentHeight;
546-
this.layout({ editorHeight: true });
547-
}
548-
}));
549-
550-
originalCell.resolveTextModelRef().then(ref => {
551-
this._register(ref);
552-
553-
const textModel = ref.object.textEditorModel;
554-
this._editor.setModel(textModel);
555-
556-
this._layoutInfo.editorHeight = this._editor.getContentHeight();
557-
this.layout({ editorHeight: true });
558-
});
559-
}
560-
561-
562-
onDidLayoutChange(event: CellDiffViewModelLayoutChangeEvent): void {
563-
if (event.outerWidth !== undefined) {
564-
this.layout({ outerWidth: true });
565-
}
566-
}
567-
568-
layout(state: { outerWidth?: boolean, editorHeight?: boolean, metadataEditor?: boolean, outputEditor?: boolean }) {
569-
if (state.editorHeight || state.outerWidth) {
570-
this._editor.layout({
571-
width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true),
572-
height: this._layoutInfo.editorHeight
573-
});
574-
}
575-
576-
if (state.metadataEditor || state.outerWidth) {
577-
this._metadataEditor?.layout({
578-
width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true),
579-
height: this._layoutInfo.metadataHeight
580-
});
581-
}
582-
583-
if (state.outputEditor || state.outerWidth) {
584-
this._outputEditor?.layout({
585-
width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true),
586-
height: this._layoutInfo.outputHeight
587-
});
588-
}
589-
590-
this.layoutNotebookCell();
591-
}
592-
}
593-
594509
export class DeletedCell extends AbstractCellRenderer {
595510
private _editor!: CodeEditorWidget;
596511
constructor(
@@ -794,7 +709,8 @@ export class ModifiedCell extends AbstractCellRenderer {
794709

795710
this._editor = this.instantiationService.createInstance(DiffEditorWidget, this._editorContainer, {
796711
...fixedDiffEditorOptions,
797-
overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode()
712+
overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(),
713+
originalEditable: false
798714
});
799715
DOM.addClass(this._editorContainer, 'diff');
800716

src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
163163
if (originalCell.getHashValue() === modifiedCell.getHashValue()) {
164164
cellDiffViewModels.push(new CellDiffViewModel(
165165
originalCell,
166-
undefined,
166+
modifiedCell,
167167
'unchanged',
168168
this._eventDispatcher!
169169
));

src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
1717
import { CellDiffViewModel } from 'vs/workbench/contrib/notebook/browser/diff/celllDiffViewModel';
1818
import { CellDiffRenderTemplate, INotebookTextDiffEditor } from 'vs/workbench/contrib/notebook/browser/diff/common';
1919
import { isMacintosh } from 'vs/base/common/platform';
20-
import { UnchangedCell, DeletedCell, InsertCell, ModifiedCell } from 'vs/workbench/contrib/notebook/browser/diff/cellComponents';
20+
import { DeletedCell, InsertCell, ModifiedCell } from 'vs/workbench/contrib/notebook/browser/diff/cellComponents';
2121

2222
export class NotebookCellTextDiffListDelegate implements IListVirtualDelegate<CellDiffViewModel> {
2323
// private readonly lineHeight: number;
@@ -64,7 +64,7 @@ export class CellDiffRenderer implements IListRenderer<CellDiffViewModel, CellDi
6464
templateData.container.innerText = '';
6565
switch (element.type) {
6666
case 'unchanged':
67-
templateData.elementDisposables.add(this.instantiationService.createInstance(UnchangedCell, this.notebookEditor, element, templateData));
67+
templateData.elementDisposables.add(this.instantiationService.createInstance(ModifiedCell, this.notebookEditor, element, templateData));
6868
return;
6969
case 'delete':
7070
templateData.elementDisposables.add(this.instantiationService.createInstance(DeletedCell, this.notebookEditor, element, templateData));

0 commit comments

Comments
 (0)