Skip to content

Commit

Permalink
Merge pull request #749 from glebovmaksim/fix-700-formatting
Browse files Browse the repository at this point in the history
Fix top level formatting (#700)
  • Loading branch information
PEZ committed Aug 18, 2020
2 parents c9d525c + 825ae88 commit 56a7bd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
Changes to Calva.

## [Unreleased]
- Fix: [Backspace is not working properly in the output window](https://github.com/BetterThanTomorrow/calva/issues/700)

## [2.0.120] - 2020-08-17
- Fix: [Interrupting evaluations produces extra output and no prompt](https://github.com/BetterThanTomorrow/calva/issues/738)
Expand Down
26 changes: 15 additions & 11 deletions src/calva-fmt/src/format.ts
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import * as config from './config';
import * as outputWindow from '../../results-output/results-doc'
import { getIndent, getDocument, getDocumentOffset, MirroredDocument } from "../../doc-mirror";
const { formatTextAtRange, formatTextAtIdx, formatTextAtIdxOnType, formatText, cljify, jsify } = require('../../../out/cljs-lib/cljs-lib');

Expand Down Expand Up @@ -80,18 +81,21 @@ export function formatPosition(editor: vscode.TextEditor, onType: boolean = fals
editor.selection = new vscode.Selection(doc.positionAt(formattedInfo.newIndex), doc.positionAt(formattedInfo.newIndex))
return onFulfilled;
});
} else {
if (formattedInfo) {
return new Promise((resolve, _reject) => {
if (formattedInfo.newIndex != formattedInfo.previousIndex) {
editor.selection = new vscode.Selection(doc.positionAt(formattedInfo.newIndex), doc.positionAt(formattedInfo.newIndex));
}
resolve(true);
});
} else {
return formatRange(doc, new vscode.Range(doc.positionAt(0), doc.positionAt(doc.getText().length)))
}
}
if (formattedInfo) {
return new Promise((resolve, _reject) => {
if (formattedInfo.newIndex != formattedInfo.previousIndex) {
editor.selection = new vscode.Selection(doc.positionAt(formattedInfo.newIndex), doc.positionAt(formattedInfo.newIndex));
}
resolve(true);
});
}
if (!onType && !outputWindow.isResultsDoc(doc)) {
return formatRange(doc, new vscode.Range(doc.positionAt(0), doc.positionAt(doc.getText().length)))
}
return new Promise((resolve, _reject) => {
resolve(true);
});
}

export function formatPositionCommand(editor: vscode.TextEditor) {
Expand Down

0 comments on commit 56a7bd7

Please sign in to comment.