Skip to content

Commit

Permalink
fix indent of new cells
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrik committed Aug 19, 2022
1 parent 71e4918 commit fb35441
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/NotebookProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -83,6 +84,7 @@ function parseClojure(content: string): vscode.NotebookCellData[] {
languageId: 'clojure',
metadata: {
leading: leading,
indent,
range,
richComment: true,
trailing: '',
Expand All @@ -100,6 +102,7 @@ function parseClojure(content: string): vscode.NotebookCellData[] {
kind: vscode.NotebookCellKind.Code,
languageId: 'clojure',
metadata: {
indent: 0,
leading: '',
trailing: '',
},
Expand All @@ -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;
}
Expand Down

0 comments on commit fb35441

Please sign in to comment.