From 9cadc9d4e9476408fd74c966fa37abc9886de314 Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Mon, 8 Apr 2024 16:17:24 +0200 Subject: [PATCH] Fix notebook cell EOL splitting (#13574) --- .../main/browser/notebooks/notebook-dto.ts | 2 +- .../src/plugin/notebook/notebook-document.ts | 19 ++----------------- .../src/plugin/notebook/notebooks.ts | 11 ++--------- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/packages/plugin-ext/src/main/browser/notebooks/notebook-dto.ts b/packages/plugin-ext/src/main/browser/notebooks/notebook-dto.ts index 491613ff55267..b80f7b05db948 100644 --- a/packages/plugin-ext/src/main/browser/notebooks/notebook-dto.ts +++ b/packages/plugin-ext/src/main/browser/notebooks/notebook-dto.ts @@ -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, diff --git a/packages/plugin-ext/src/plugin/notebook/notebook-document.ts b/packages/plugin-ext/src/plugin/notebook/notebook-document.ts index 9ca4db6f35ee1..456e218b3d250 100644 --- a/packages/plugin-ext/src/plugin/notebook/notebook-document.ts +++ b/packages/plugin-ext/src/plugin/notebook/notebook-document.ts @@ -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 { @@ -49,7 +48,7 @@ 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, @@ -57,7 +56,6 @@ export class Cell { uri: cell.uri, isDirty: false, versionId: 1, - notebook, modeId: '' }; } @@ -348,8 +346,6 @@ export class NotebookDocument implements Disposable { } const contentChangeEvents: RawContentChangeEvent[] = []; - const addedCellDocuments: ModelAddedData[] = []; - const removedCellDocuments: UriComponents[] = []; splices.reverse().forEach(splice => { const cellDtos = splice.newItems; @@ -357,18 +353,8 @@ export class NotebookDocument implements Disposable { 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; @@ -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); diff --git a/packages/plugin-ext/src/plugin/notebook/notebooks.ts b/packages/plugin-ext/src/plugin/notebook/notebooks.ts index d21a99588636a..975dbd752e42e 100644 --- a/packages/plugin-ext/src/plugin/notebook/notebooks.ts +++ b/packages/plugin-ext/src/plugin/notebook/notebooks.ts @@ -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'; @@ -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);