Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notebook cell EOL splitting #13574

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading