Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement preventing auto-scroll on new output #6062

Merged
8 commits merged into from
Jul 9, 2020
Merged

Conversation

carlos-zamora
Copy link
Member

@carlos-zamora carlos-zamora commented May 21, 2020

Summary of the Pull Request

Updates the Terminal's scroll response to new output. The Terminal will not automatically scroll if...

  • a selection is active, or
  • the viewport is at the bottom of the scroll history

References

#2529 - Spec
#3863 - Implementation

PR Checklist

Detailed Description of the Pull Request / Additional comments

Updates the _scrollOffset value properly in TerminalCore when the cursor moves. We calculate a new _scrollOffset based on if we are circling the buffer and how far below the mutable bottom is.

We specifically check for if a selection is active and if the viewport is at the bottom, then use that as a condition for deciding if we should update _scrollOffset to the new calculated value or 0 (the bottom of the scroll history).

Validation Steps Performed

Manual testing. Though I should add automated tests.

  • new output
  • new output when circling
  • new output when circling and viewport is at the top

@carlos-zamora carlos-zamora added the Product-Terminal The new Windows Terminal. label May 21, 2020
@ghost ghost added Area-Settings Issues related to settings and customizability, for console or terminal Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. labels May 21, 2020
src/cascadia/TerminalApp/Profile.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/Profile.cpp Outdated Show resolved Hide resolved
src/inc/DefaultSettings.h Outdated Show resolved Hide resolved
@johnburnett
Copy link

This is probably coming in way to late, but having just found this - can we call this "scrollOnOutput"? The only reason I found this PR is because it's linked through other issues that reference "scroll" in their name. "snap" feels very obscure compared to what this setting actually controls (the scroll position).

@carlos-zamora
Copy link
Member Author

carlos-zamora commented Jun 24, 2020

This is probably coming in way to late, but having just found this - can we call this "scrollOnOutput"? The only reason I found this PR is because it's linked through other issues that reference "scroll" in their name. "snap" feels very obscure compared to what this setting actually controls (the scroll position).

Fair request. Copying this comment over to #2529 for discussion there.

EDIT: wait, it's already there hahaha

@carlos-zamora carlos-zamora changed the title Implement SnapOnOutput Setting Implement preventing auto-scroll on new output Jul 7, 2020
@ghost ghost added Issue-Task It's a feature request, but it doesn't really need a major design. Priority-1 A description (P1) labels Jul 7, 2020
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever

@carlos-zamora carlos-zamora added the Needs-Second It's a PR that needs another sign-off label Jul 8, 2020
@ghost ghost requested review from zadjii-msft, miniksa and leonMSFT July 8, 2020 16:48
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test?

@carlos-zamora
Copy link
Member Author

Add a test?

I think we don't have scrolling-related tests, but I'll double check. So nobody come along and automerge this plz!

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block for a test

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 8, 2020
@carlos-zamora
Copy link
Member Author

block for a test

I hate that you're in the right for doing this... hahaha

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 8, 2020
@carlos-zamora
Copy link
Member Author

Ok. I spent most of today trying to add a test to ScrollTest. I copied it below.

That should totally work. All I'm doing is writing lines of text to the buffer, and comparing the scroll offset to what it should be.

It doesn't though because we need a callback to the scrollback in TermControl. Spoke with Dustin and this just doesn't feel right. Like, scrolling should be pretty self sustained.

So, I created #6842 to track this better.

Test Code
void ScrollTest::TestConditionalAutoscrolling()
{
    // When new output is generated, we should only scroll to it when...
    // - no selection is active, and
    // - the viewport is already at the bottom of the scroll history

    Log::Comment(L"Watch out - this test takes a while to run, and won't "
                 L"output anything unless in encounters an error. This is expected.");

    auto& termTb = *_term->_buffer;

    const auto totalBufferSize = termTb.GetSize().Height();

    // We're outputting like 18000 lines of text here, so emitting 18000*4 lines
    // of output to the console is actually quite unnecessary
    WEX::TestExecution::SetVerifyOutput settings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);

    // Emit a bunch of newlines to test scrolling.
    auto scrollAmount = 0;
    for (auto currentRow = 0; currentRow < totalBufferSize * 2; currentRow++)
    {
        *_scrollBarNotification = std::nullopt;
        _renderTarget->Reset();

        _term->_WriteBuffer(L"X\r\n");

        if (currentRow < TerminalViewHeight)
        {
            // no scrolling is expected
            VERIFY_ARE_EQUAL(0, _term->_scrollOffset);
        }
        else if (currentRow < TerminalViewHeight * 2)
        {
            // keep track of scrolling
            ++scrollAmount;
            VERIFY_ARE_EQUAL(scrollAmount, _term->_scrollOffset);
        }
        else if (currentRow == TerminalViewHeight * 2)
        {
            // create a selection
            Log::Comment(L"Create a selection to pause scrolling");
            _term->SelectNewRegion({ 0, static_cast<SHORT>(currentRow) }, { 5, static_cast<SHORT>(currentRow) });

            VERIFY_ARE_EQUAL(scrollAmount, _term->_scrollOffset);
        }
        else if (currentRow < totalBufferSize)
        {
            // scrolling is unchanged because of selection
            VERIFY_ARE_EQUAL(scrollAmount, _term->_scrollOffset);
        }
        else if (scrollAmount > 0)
        {
            // circling the buffer
            // we should be scrolling up to keep the same content in the viewport
            --scrollAmount;
            VERIFY_ARE_EQUAL(scrollAmount, _term->_scrollOffset);
        }
        else
        {
            // still circling the buffer
            // we can't scroll up anymore
            VERIFY_ARE_EQUAL(0, _term->_scrollOffset);
        }
    }
}

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good enough for me

@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jul 9, 2020
@ghost
Copy link

ghost commented Jul 9, 2020

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 9e26c02 into master Jul 9, 2020
@ghost ghost deleted the dev/cazamor/snapOnOutput branch July 9, 2020 11:24
@ghost
Copy link

ghost commented Jul 22, 2020

🎉Windows Terminal Preview v1.2.2022.0 has been released which incorporates this pull request.:tada:

Handy links:

ghost pushed a commit that referenced this pull request Aug 11, 2020
)

If you scroll up to view the scrollback, then we want the viewport to
"stay in place", as new output comes in (see #6062). This works fine up
until the buffer circles. In this case, the mutable viewport isn't
actually moving, so we never set `updatedViewport` to true. 

This regressed in #6062
Closes #7222
DHowett pushed a commit that referenced this pull request Aug 24, 2020
)

If you scroll up to view the scrollback, then we want the viewport to
"stay in place", as new output comes in (see #6062). This works fine up
until the buffer circles. In this case, the mutable viewport isn't
actually moving, so we never set `updatedViewport` to true.

This regressed in #6062
Closes #7222

(cherry picked from commit bc642bb)
@brandon-kohn
Copy link

I'm using 1.17.1023 and when I'm compiling and scroll back to see an error after a few moments it jumps back down to the bottom of buffer. This happens whether I select some text or not.

@zadjii-msft
Copy link
Member

@brandon-kohn Interesting - mind filing a new issue? This should have shipped nearly 3 years ago now, so whatever you're seeing is probably unrelated to this original PR. I want to make sure we don't lose track of it.

I'd also check the snapOnInput setting (some mysterious keys that aren't letters sometimes still trigger the snapping). More details about your environment might be helpful too, what tools, WSL or not, tmux or not, etc, etc.

Thanks!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Issue-Task It's a feature request, but it doesn't really need a major design. Needs-Second It's a PR that needs another sign-off Priority-1 A description (P1) Product-Terminal The new Windows Terminal.
Projects
None yet
6 participants