Skip to content

Commit

Permalink
Fix notebook cell EOL splitting (#13574)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew authored Apr 8, 2024
1 parent bce99c2 commit 9cadc9d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export namespace NotebookDto {
return {
handle: cell.handle,
uri: cell.uri.toComponents(),
source: cell.text.split(eol),
source: cell.text.split(/\r?\n/g),
eol,
language: cell.language,
cellKind: cell.cellKind,
Expand Down
19 changes: 2 additions & 17 deletions packages/plugin-ext/src/plugin/notebook/notebook-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { Disposable, URI } from '@theia/core';
import * as typeConverters from '../type-converters';
import { ModelAddedData, NotebookCellDto, NotebookCellsChangedEventDto, NotebookModelAddedData, NotebookOutputDto } from '../../common';
import { NotebookRange } from '../types-impl';
import { UriComponents } from '../../common/uri-components';
import { DocumentsExtImpl } from '../documents';

class RawContentChangeEvent {
Expand All @@ -49,15 +48,14 @@ class RawContentChangeEvent {

export class Cell {

static asModelAddData(notebook: theia.NotebookDocument, cell: NotebookCellDto): ModelAddedData & { notebook: theia.NotebookDocument } {
static asModelAddData(cell: NotebookCellDto): ModelAddedData {
return {
EOL: cell.eol,
lines: cell.source,
languageId: cell.language,
uri: cell.uri,
isDirty: false,
versionId: 1,
notebook,
modeId: ''
};
}
Expand Down Expand Up @@ -348,27 +346,15 @@ export class NotebookDocument implements Disposable {
}

const contentChangeEvents: RawContentChangeEvent[] = [];
const addedCellDocuments: ModelAddedData[] = [];
const removedCellDocuments: UriComponents[] = [];

splices.reverse().forEach(splice => {
const cellDtos = splice.newItems;
const newCells = cellDtos.map((cell: NotebookCellDto) => {

const extCell = new Cell(this, this.editorsAndDocuments, cell);
if (!initialization) {
addedCellDocuments.push(Cell.asModelAddData(this.apiNotebook, cell));
this.editorsAndDocuments.$acceptEditorsAndDocumentsDelta({
addedDocuments: [
{
uri: cell.uri,
versionId: 1,
lines: cell.source,
EOL: cell.eol,
modeId: '',
isDirty: false
}
]
addedDocuments: [Cell.asModelAddData(cell)]
});
}
return extCell;
Expand All @@ -377,7 +363,6 @@ export class NotebookDocument implements Disposable {
const changeEvent = new RawContentChangeEvent(splice.start, splice.deleteCount, [], newCells);
const deletedItems = this.cells.splice(splice.start, splice.deleteCount, ...newCells);
for (const cell of deletedItems) {
removedCellDocuments.push(cell.uri.toComponents());
changeEvent.deletedItems.push(cell.apiCell);
}
contentChangeEvents.push(changeEvent);
Expand Down
11 changes: 2 additions & 9 deletions packages/plugin-ext/src/plugin/notebook/notebooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { UriComponents } from '../../common/uri-components';
import { CommandsConverter } from '../command-registry';
import * as typeConverters from '../type-converters';
import { BinaryBuffer } from '@theia/core/lib/common/buffer';
import { NotebookDocument } from './notebook-document';
import { Cell, NotebookDocument } from './notebook-document';
import { NotebookEditor } from './notebook-editor';
import { EditorsAndDocumentsExtImpl } from '../editors-and-documents';
import { DocumentsExtImpl } from '../documents';
Expand Down Expand Up @@ -243,14 +243,7 @@ export class NotebooksExtImpl implements NotebooksExt {
this.documents.set(uri.toString(), document);

this.textDocumentsAndEditors.$acceptEditorsAndDocumentsDelta({
addedDocuments: modelData.cells.map(cell => ({
uri: cell.uri,
versionId: 1,
lines: cell.source,
EOL: cell.eol,
modeId: '',
isDirty: false
}))
addedDocuments: modelData.cells.map(cell => Cell.asModelAddData(cell))
});

this.onDidOpenNotebookDocumentEmitter.fire(document.apiNotebook);
Expand Down

0 comments on commit 9cadc9d

Please sign in to comment.