Skip to content

Conversation

@vididvidid
Copy link
Contributor

@vididvidid vididvidid commented Oct 6, 2025

Summary of the Pull Request

This PR fixes a bug where programmatic scrolling would get stuck. The fix makes the "snap-on-input" feature conditional, activating it only for modern applications that use Virtual Terminal (VT) processing. This restores correct scrolling behavior for legacy applications without removing the feature for new ones.

References and Relevant Issues

Fixes #19390: OpenConsole: Cursor visibility prevents programmatic scrolling

Detailed Description of the Pull Request / Additional comments

The "snap-on-input" feature introduced in a previous PR caused an unintended side effect for older console programs that use the SetConsoleWindowInfo API to manage their own viewport. When such a program tried to scroll using a key press, the snap feature would immediately pull the view back to the cursor's position, causing the screen to flicker and get stuck.

This fix makes the snap-on-input feature smarter by checking the application's mode first.

Validation Steps Performed

Compiled the minimal C++ reproduction case from issue #19390.

Ran the test executable inside the newly built OpenConsole.exe.

Confirmed that scrolling with the Up/Down arrow keys now works correctly, even with a visible cursor. The view no longer flickers or gets stuck when the cursor moves outside the viewport.

Closes #19390

@vididvidid
Copy link
Contributor Author

@microsoft-github-policy-service agree

Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

I'm OOTL but this makes sense to me. 👍

void SetCursorType(const CursorType Type, const bool setMain = false) noexcept;

void SetSnapOnInputEnabled(const bool enabled) noexcept { _snapOnInputEnabled = enabled; }
[[nodiscard]] bool IsSnapOnInputEnabled() const noexcept { return _snapOnInputEnabled; }
Copy link
Member

Choose a reason for hiding this comment

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

For consistency I think these should go into the .cpp file (they aren't templates).


void SCREEN_INFORMATION::MakeCursorVisible(til::point position)
{

Copy link
Member

Choose a reason for hiding this comment

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

Extra.

}
}


Copy link
Member

Choose a reason for hiding this comment

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

Extra.

@DHowett
Copy link
Member

DHowett commented Oct 6, 2025

@lhecker qq about your thought process here - do you have a gut feeling about introducing new (possibly torn) state boolean rather than just the input mode directly?

DHowett
DHowett previously requested changes Oct 6, 2025
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.

(want to noodle about this a little bit, sorry!)

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 6, 2025
@lhecker
Copy link
Member

lhecker commented Oct 6, 2025

Oh right I didn't think of that, since the input mode is stored elsewhere. Regarding duplicating it: my thought was that if we were to add a user setting for this (hypothetically), I would make it a bitfield, similar to the new "cursor inhibitors".

For now, I suppose it makes sense to just ask the input mode.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 6, 2025
@vididvidid
Copy link
Contributor Author

I think I just chose the long way to do it. There can be another way, like this:

Just change the file input.cpp and add the following line in the HandleGenericKeyEvent Function :

if (WI_IsFlagSet(buffer.OutputMode, ENABLE_VIRTUAL_TERMINAL_PROCESSING))
{
    buffer.SnapOnInput(keyEvent.wVirtualKeyCode);
}

@vididvidid
Copy link
Contributor Author

Do you want me to remove all of that and prefer this change...

@vididvidid vididvidid requested review from DHowett and lhecker October 6, 2025 21:32
@carlos-zamora
Copy link
Member

Bump @DHowett and @lhecker for feedback

@lhecker
Copy link
Member

lhecker commented Nov 4, 2025

Just change the file input.cpp and add the following line in the HandleGenericKeyEvent Function : [...]

Yes, that's what Dustin meant with his comment. I think we should do that.

@vididvidid
Copy link
Contributor Author

@DHowett and @lhecker I've updated the pull request. I've reverted the old changes (like _snapOnInputEnabled) and applied the simpler fix to check buffer.OutputMode directly in HandleGenericKeyEvent, as we discussed.

This should be ready for another review. Thanks!

@lhecker lhecker added this to the Terminal v1.25 milestone Nov 18, 2025
@carlos-zamora
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@carlos-zamora
Copy link
Member

(extracted from PR body)
Here is a video demonstrating the fix:

MicrosoftScreenFix.mp4

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

Nice and simple. Thanks! 🙂 Sorry for the delays!

@carlos-zamora carlos-zamora dismissed DHowett’s stale review November 19, 2025 18:34

Looks like the original concern was regarding a possible torn state (see #19414 (comment))

New implementation removed that issue

@carlos-zamora carlos-zamora enabled auto-merge (squash) November 19, 2025 18:34
@carlos-zamora carlos-zamora merged commit c28610d into microsoft:main Nov 19, 2025
13 of 15 checks passed
DHowett pushed a commit that referenced this pull request Nov 24, 2025
…mmatic scroll (#19414)

## Summary of the Pull Request
This PR fixes a bug where programmatic scrolling would get stuck. The
fix makes the "snap-on-input" feature conditional, activating it only
for modern applications that use Virtual Terminal (VT) processing. This
restores correct scrolling behavior for legacy applications without
removing the feature for new ones.

## References and Relevant Issues
Fixes #19390: OpenConsole: Cursor visibility prevents programmatic
scrolling

## Detailed Description of the Pull Request / Additional comments
The "snap-on-input" feature introduced in a previous PR caused an
unintended side effect for older console programs that use the
SetConsoleWindowInfo API to manage their own viewport. When such a
program tried to scroll using a key press, the snap feature would
immediately pull the view back to the cursor's position, causing the
screen to flicker and get stuck.

This fix makes the snap-on-input feature smarter by checking the
application's mode first.

## Validation Steps Performed

Compiled the minimal C++ reproduction case from issue #19390.

Ran the test executable inside the newly built OpenConsole.exe.

Confirmed that scrolling with the Up/Down arrow keys now works
correctly, even with a visible cursor. The view no longer flickers or
gets stuck when the cursor moves outside the viewport.

Closes #19390

(cherry picked from commit c28610d)
Service-Card-Id: PVTI_lADOAF3p4s4BBcTlzgfZNLg
Service-Version: 1.24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenConsole: Cursor visibility prevents programmatic scrolling

4 participants