Skip to content

Commit d9b9744

Browse files
committed
content change event on piece tree and annoate TODOs
1 parent 5a9f7a4 commit d9b9744

13 files changed

Lines changed: 40 additions & 28 deletions

File tree

src/vs/editor/common/model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { Event } from 'vs/base/common/event';
67
import { IMarkdownString } from 'vs/base/common/htmlContent';
78
import { IDisposable } from 'vs/base/common/lifecycle';
89
import { URI } from 'vs/base/common/uri';
@@ -1277,6 +1278,7 @@ export class ValidAnnotatedEditOperation implements IIdentifiedSingleEditOperati
12771278
* @internal
12781279
*/
12791280
export interface IReadonlyTextBuffer {
1281+
onDidChangeContent: Event<void>;
12801282
equals(other: ITextBuffer): boolean;
12811283
mightContainRTL(): boolean;
12821284
mightContainNonBasicASCII(): boolean;

src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { Emitter, Event } from 'vs/base/common/event';
67
import * as strings from 'vs/base/common/strings';
78
import { Position } from 'vs/editor/common/core/position';
89
import { Range } from 'vs/editor/common/core/range';
@@ -11,6 +12,7 @@ import { PieceTreeBase, StringBuffer } from 'vs/editor/common/model/pieceTreeTex
1112
import { SearchData } from 'vs/editor/common/model/textModelSearch';
1213
import { countEOL, StringEOL } from 'vs/editor/common/model/tokensStore';
1314
import { TextChange } from 'vs/editor/common/model/textChange';
15+
import { IDisposable } from 'vs/base/common/lifecycle';
1416

1517
export interface IValidatedEditOperation {
1618
sortIndex: number;
@@ -30,18 +32,24 @@ export interface IReverseSingleEditOperation extends IValidEditOperation {
3032
sortIndex: number;
3133
}
3234

33-
export class PieceTreeTextBuffer implements ITextBuffer {
35+
export class PieceTreeTextBuffer implements ITextBuffer, IDisposable {
3436
private readonly _pieceTree: PieceTreeBase;
3537
private readonly _BOM: string;
3638
private _mightContainRTL: boolean;
3739
private _mightContainNonBasicASCII: boolean;
3840

41+
private readonly _onDidChangeContent: Emitter<void> = new Emitter<void>();
42+
public readonly onDidChangeContent: Event<void> = this._onDidChangeContent.event;
43+
3944
constructor(chunks: StringBuffer[], BOM: string, eol: '\r\n' | '\n', containsRTL: boolean, isBasicASCII: boolean, eolNormalized: boolean) {
4045
this._BOM = BOM;
4146
this._mightContainNonBasicASCII = !isBasicASCII;
4247
this._mightContainRTL = containsRTL;
4348
this._pieceTree = new PieceTreeBase(chunks, eol, eolNormalized);
4449
}
50+
dispose(): void {
51+
this._onDidChangeContent.dispose();
52+
}
4553

4654
// #region TextBuffer
4755
public equals(other: ITextBuffer): boolean {
@@ -360,6 +368,8 @@ export class PieceTreeTextBuffer implements ITextBuffer {
360368
}
361369
}
362370

371+
this._onDidChangeContent.fire();
372+
363373
return new ApplyEditsResult(
364374
reverseOperations,
365375
contentChanges,

src/vs/workbench/contrib/notebook/browser/notebookEditorInput.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export class NotebookEditorInput extends EditorInput {
9191
}
9292

9393
this.textModel = await this.notebookService.modelManager.resolve(this.resource, this.viewType!);
94+
95+
this._register(this.textModel.onDidChangeDirty(() => {
96+
this._onDidChangeDirty.fire();
97+
}));
98+
9499
return this.textModel;
95100
}
96101

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> implements ID
527527
}
528528
}
529529

530-
// TODO@rebornix TEST & Fix potential bugs
531530
// List items have real dynamic heights, which means after we set `scrollTop` based on the `elementTop(index)`, the element at `index` might still be removed from the view once all relayouting tasks are done.
532531
// For example, we scroll item 10 into the view upwards, in the first round, items 7, 8, 9, 10 are all in the viewport. Then item 7 and 8 resize themselves to be larger and finally item 10 is removed from the view.
533532
// To ensure that item 10 is always there, we need to scroll item 10 to the top edge of the viewport.

src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ const DRAGOVER_CLASS = 'cell-dragover';
468468
type DragImageProvider = () => HTMLElement;
469469

470470
export class CellDragAndDropController {
471-
// TODO roblou - should probably use dataTransfer here, but any dataTransfer set makes the editor think I am dropping a file, need
471+
// TODO@roblourens - should probably use dataTransfer here, but any dataTransfer set makes the editor think I am dropping a file, need
472472
// to figure out how to prevent that
473473
private currentDraggedCell: ICellViewModel | undefined;
474474

@@ -488,7 +488,7 @@ export class CellDragAndDropController {
488488
};
489489

490490
templateData.disposables.add(domEvent(dragHandle, DOM.EventType.DRAG_END)(() => {
491-
// TODO
491+
// TODO@roblourens
492492
(this.notebookEditor.getInnerWebview() as any)!.element.style['pointer-events'] = '';
493493

494494
// Note, templateData may have a different element rendered into it by now
@@ -646,7 +646,7 @@ class CodeCellDragImageRenderer {
646646
getDragImage(templateData: CodeCellRenderTemplate): HTMLElement {
647647
let dragImage = this._getDragImage(templateData);
648648
if (!dragImage) {
649-
// TODO I don't think this can happen
649+
// TODO@roblourens I don't think this can happen
650650
dragImage = document.createElement('div');
651651
dragImage.textContent = '1 cell';
652652
}
@@ -812,7 +812,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
812812
} else if (metadata.runState === NotebookCellRunState.Error) {
813813
templateData.cellRunStatusContainer.innerHTML = renderCodicons('$(error)');
814814
} else if (metadata.runState === NotebookCellRunState.Running) {
815-
// TODO should extensions be able to customize the status message while running to show progress?
815+
// TODO@roblourens should extensions be able to customize the status message while running to show progress?
816816
templateData.cellStatusMessageContainer.textContent = nls.localize('cellRunningStatus', "Running");
817817
templateData.cellRunStatusContainer.innerHTML = renderCodicons('$(sync~spin)');
818818
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export class CodeCell extends Disposable {
217217

218218
this.templateData.outputContainer!.style.display = 'block';
219219
// there are outputs, we need to calcualte their sizes and trigger relayout
220-
// @todo, if there is no resizable output, we should not check their height individually, which hurts the performance
220+
// @TODO@rebornix, if there is no resizable output, we should not check their height individually, which hurts the performance
221221
for (let index = 0; index < this.viewCell.outputs.length; index++) {
222222
const currOutput = this.viewCell.outputs[index];
223223

@@ -376,7 +376,7 @@ export class CodeCell extends Disposable {
376376
} else {
377377
// static output
378378

379-
// @TODO, if we stop checking output height, we need to evaluate it later when checking the height of output container
379+
// @TODO@rebornix, if we stop checking output height, we need to evaluate it later when checking the height of output container
380380
let clientHeight = outputItemDiv.clientHeight;
381381
this.viewCell.updateOutputHeight(index, clientHeight);
382382
}

src/vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export abstract class BaseCellViewModel extends Disposable implements ICellViewM
6464
}
6565
}
6666

67-
// TODO - move any "run"/"status" concept to Code-specific places
67+
// TODO@roblourens - move any "run"/"status" concept to Code-specific places
6868
private _currentTokenSource: CancellationTokenSource | undefined;
6969
public set currentTokenSource(v: CancellationTokenSource | undefined) {
7070
this._currentTokenSource = v;

src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
180180
this._register(ref);
181181
this._register(this._textModel.onDidChangeContent(() => {
182182
this.editState = CellEditState.Editing;
183-
this.model.contentChange();
184183
this._onDidChangeState.fire({ contentChanged: true });
185184
}));
186185
}

src/vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ export class MarkdownCellViewModel extends BaseCellViewModel implements ICellVie
134134
this._textModel = ref.object.textEditorModel;
135135
this._register(ref);
136136
this._register(this._textModel.onDidChangeContent(() => {
137-
this.model.contentChange();
138137
this._html = null;
139138
this._onDidChangeState.fire({ contentChanged: true });
140139
}));

src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import { PieceTreeTextBufferBuilder } from 'vs/editor/common/model/pieceTreeText
99
import { URI } from 'vs/base/common/uri';
1010
import * as model from 'vs/editor/common/model';
1111
import { Range } from 'vs/editor/common/core/range';
12+
import { Disposable } from 'vs/base/common/lifecycle';
1213

13-
export class NotebookCellTextModel implements ICell {
14+
export class NotebookCellTextModel extends Disposable implements ICell {
1415
private _onDidChangeOutputs = new Emitter<NotebookCellOutputsSplice[]>();
1516
onDidChangeOutputs: Event<NotebookCellOutputsSplice[]> = this._onDidChangeOutputs.event;
1617

@@ -60,6 +61,11 @@ export class NotebookCellTextModel implements ICell {
6061
builder.acceptChunk(this._source.join('\n'));
6162
const bufferFactory = builder.finish(true);
6263
this._textBuffer = bufferFactory.create(model.DefaultEndOfLine.LF);
64+
65+
this._register(this._textBuffer.onDidChangeContent(() => {
66+
this._onDidChangeContent.fire();
67+
}));
68+
6369
return this._textBuffer;
6470
}
6571

@@ -72,6 +78,7 @@ export class NotebookCellTextModel implements ICell {
7278
outputs: IOutput[],
7379
metadata: NotebookCellMetadata | undefined
7480
) {
81+
super();
7582
this._outputs = outputs;
7683
this._metadata = metadata;
7784
}
@@ -80,7 +87,6 @@ export class NotebookCellTextModel implements ICell {
8087
const lineCount = this.textBuffer.getLineCount();
8188
const fullRange = new Range(1, 1, lineCount, this.textBuffer.getLineLength(lineCount) + 1);
8289

83-
// todo@rebornix eol?
8490
const eol = this.textBuffer.getEOL();
8591
if (eol === '\n') {
8692
return this.textBuffer.getValueInRange(fullRange, model.EndOfLinePreference.LF);
@@ -89,10 +95,6 @@ export class NotebookCellTextModel implements ICell {
8995
}
9096
}
9197

92-
contentChange() {
93-
this._onDidChangeContent.fire();
94-
}
95-
9698
spliceNotebookCellOutputs(splices: NotebookCellOutputsSplice[]): void {
9799
splices.reverse().forEach(splice => {
98100
this.outputs.splice(splice[0], splice[1], ...splice[2]);

0 commit comments

Comments
 (0)