Skip to content

Commit fb35441

Browse files
committed
fix indent of new cells
1 parent 71e4918 commit fb35441

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/NotebookProvider.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function parseClojure(content: string): vscode.NotebookCellData[] {
7373
while (commentStartCursor.forwardSexp()) {
7474
const range = commentStartCursor.rangeForDefun(commentStartCursor.offsetStart);
7575
let leading = '';
76+
const indent = commentStartCursor.doc.getRowCol(range[0])[1]; // will break with tabs?
7677

7778
leading = content.substring(previouseEnd, range[0]);
7879
previouseEnd = range[1];
@@ -83,6 +84,7 @@ function parseClojure(content: string): vscode.NotebookCellData[] {
8384
languageId: 'clojure',
8485
metadata: {
8586
leading: leading,
87+
indent,
8688
range,
8789
richComment: true,
8890
trailing: '',
@@ -100,6 +102,7 @@ function parseClojure(content: string): vscode.NotebookCellData[] {
100102
kind: vscode.NotebookCellKind.Code,
101103
languageId: 'clojure',
102104
metadata: {
105+
indent: 0,
103106
leading: '',
104107
trailing: '',
105108
},
@@ -110,13 +113,15 @@ function parseClojure(content: string): vscode.NotebookCellData[] {
110113
}
111114

112115
function writeCellsToClojure(cells: vscode.NotebookCellData[]) {
113-
return cells.reduce((acc, x) => {
116+
return cells.reduce((acc, x, index) => {
114117
if (x.kind === vscode.NotebookCellKind.Code) {
115118
let result = '';
116119

117120
// created inside the notebook
118121
if (undefined === x.metadata.leading) {
119-
result = '\n\n' + x.value;
122+
const indent = index > 0 ? _.repeat(' ', cells[index - 1].metadata.indent) : '';
123+
124+
result = '\n\n' + indent + x.value;
120125
} else {
121126
result = x.metadata.leading + x.value + x.metadata.trailing;
122127
}

0 commit comments

Comments
 (0)