From fb35441d1f931282fedab1786e33c122f7f40a34 Mon Sep 17 00:00:00 2001 From: Lukas Domagala Date: Fri, 19 Aug 2022 18:23:23 +0200 Subject: [PATCH] fix indent of new cells --- src/NotebookProvider.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/NotebookProvider.ts b/src/NotebookProvider.ts index c44d0604a..7438874c4 100644 --- a/src/NotebookProvider.ts +++ b/src/NotebookProvider.ts @@ -73,6 +73,7 @@ function parseClojure(content: string): vscode.NotebookCellData[] { while (commentStartCursor.forwardSexp()) { const range = commentStartCursor.rangeForDefun(commentStartCursor.offsetStart); let leading = ''; + const indent = commentStartCursor.doc.getRowCol(range[0])[1]; // will break with tabs? leading = content.substring(previouseEnd, range[0]); previouseEnd = range[1]; @@ -83,6 +84,7 @@ function parseClojure(content: string): vscode.NotebookCellData[] { languageId: 'clojure', metadata: { leading: leading, + indent, range, richComment: true, trailing: '', @@ -100,6 +102,7 @@ function parseClojure(content: string): vscode.NotebookCellData[] { kind: vscode.NotebookCellKind.Code, languageId: 'clojure', metadata: { + indent: 0, leading: '', trailing: '', }, @@ -110,13 +113,15 @@ function parseClojure(content: string): vscode.NotebookCellData[] { } function writeCellsToClojure(cells: vscode.NotebookCellData[]) { - return cells.reduce((acc, x) => { + return cells.reduce((acc, x, index) => { if (x.kind === vscode.NotebookCellKind.Code) { let result = ''; // created inside the notebook if (undefined === x.metadata.leading) { - result = '\n\n' + x.value; + const indent = index > 0 ? _.repeat(' ', cells[index - 1].metadata.indent) : ''; + + result = '\n\n' + indent + x.value; } else { result = x.metadata.leading + x.value + x.metadata.trailing; }