From 19e91c19eeff1b617f2889146df09e8bd6cf6781 Mon Sep 17 00:00:00 2001 From: glebovmaksim Date: Sun, 20 Sep 2020 17:02:37 +0300 Subject: [PATCH] Fix #792 --- CHANGELOG.md | 1 + src/results-output/results-doc.ts | 20 +++++--------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b5ebcd72..bc13cacd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Changes to Calva. ## [Unreleased] +- Fix: [Show the REPL/output with cursor at the bottom](https://github.com/BetterThanTomorrow/calva/issues/792) - [Fix: evals should be ignored during parsing](https://github.com/BetterThanTomorrow/calva/issues/763) - Fix: [Test runner can't find tests under cursor when using a custom test macro](https://github.com/BetterThanTomorrow/calva/issues/786) diff --git a/src/results-output/results-doc.ts b/src/results-output/results-doc.ts index 3d7e9180f..aa389c09c 100644 --- a/src/results-output/results-doc.ts +++ b/src/results-output/results-doc.ts @@ -156,7 +156,9 @@ export async function openResultsDoc(): Promise { export function revealResultsDoc(preserveFocus: boolean = true) { openResultsDoc().then(doc => { - vscode.window.showTextDocument(doc, getViewColumn(), preserveFocus); + vscode.window.showTextDocument(doc, getViewColumn(), preserveFocus).then(editor => { + util.scrollToBottom(editor); + }) }); } @@ -206,7 +208,6 @@ export function appendCurrentTopLevelForm() { appendFormGrabbingSessionAndNS(true); } -let scrollToBottomSub: vscode.Disposable; interface OnAppendedCallback { (insertLocation: vscode.Location): any } @@ -231,27 +232,16 @@ export function append(text: string, onAppended?: OnAppendedCallback): void { const currentContent = doc.getText(); const lastLineEmpty = currentContent.match(/\n$/) || currentContent === ''; const appendText = `${lastLineEmpty ? '' : '\n'}${ansiStrippedText}\n`; + insertPosition = doc.positionAt(Infinity); edit.insert(DOC_URI(), insertPosition, `${appendText}`); - if (scrollToBottomSub) { - scrollToBottomSub.dispose(); - } + let visibleResultsEditors: vscode.TextEditor[] = []; vscode.window.visibleTextEditors.forEach(editor => { if (isResultsDoc(editor.document)) { visibleResultsEditors.push(editor); } }); - if (visibleResultsEditors.length == 0) { - scrollToBottomSub = vscode.window.onDidChangeActiveTextEditor((editor) => { - if (isResultsDoc(editor.document)) { - util.scrollToBottom(editor); - scrollToBottomSub.dispose(); - } - }); - state.extensionContext.subscriptions.push(scrollToBottomSub); - } - vscode.workspace.applyEdit(edit).then(success => { applyingEdit = false; doc.save();