Skip to content

Commit

Permalink
Add newline if evaluation is from the prompt
Browse files Browse the repository at this point in the history
Fixes #1931
  • Loading branch information
PEZ committed Nov 1, 2022
1 parent 64ab38d commit 51a205e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes to Calva.

## [Unreleased]

- Fix: [Newline lacking before results when evaluating at the REPL prompt](https://github.com/BetterThanTomorrow/calva/issues/1931)

## [2.0.313] - 2022-10-31

- [Use format-as-you-type for Paredit](https://github.com/BetterThanTomorrow/calva/issues/1924)
Expand Down
6 changes: 6 additions & 0 deletions src/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ async function evaluateSelection(document = {}, options) {
undefined,
annotations.AnnotationStatus.PENDING
);
if (
state.extensionContext.workspaceState.get('outputWindowActive') &&
!(await outputWindow.lastLineIsEmpty())
) {
outputWindow.appendLine();
}
await evaluateCodeUpdatingUI(
code,
{ ...options, ns, line, column, filePath, session },
Expand Down
11 changes: 7 additions & 4 deletions src/results-output/results-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,13 @@ export function appendCurrentTopLevelForm() {
void appendFormGrabbingSessionAndNS(true);
}

function lastLineIsEmpty(doc: vscode.TextDocument): boolean {
const { lineCount } = doc;
const lastLine = doc.getText(new vscode.Range(lineCount - 1, 0, lineCount - 1, Infinity));
return lastLine === '';
export async function lastLineIsEmpty(): Promise<boolean> {
try {
const doc = await vscode.workspace.openTextDocument(DOC_URI());
return util.lastLineIsEmpty(doc);
} catch (error) {
console.error('Failed opening results doc', error);
}
}

function visibleResultsEditors(): vscode.TextEditor[] {
Expand Down
8 changes: 8 additions & 0 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,14 @@ function pathExists(path: string): boolean {
return fs.existsSync(path);
}

export function lastLineIsEmpty(
doc: vscode.TextDocument = vscode.window.activeTextEditor.document
): boolean {
const { lineCount } = doc;
const lastLine = doc.getText(new vscode.Range(lineCount - 1, 0, lineCount - 1, Infinity));
return lastLine === '';
}

export {
distinct,
getWordAtPosition,
Expand Down

0 comments on commit 51a205e

Please sign in to comment.