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

Cursor jumps to next line after running command same width as window. #17013

Closed
e82eric opened this issue Apr 4, 2024 · 5 comments · Fixed by #17290
Closed

Cursor jumps to next line after running command same width as window. #17013

e82eric opened this issue Apr 4, 2024 · 5 comments · Fixed by #17290
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Priority-3 A description (P3) Product-Conpty For console issues specifically related to conpty
Milestone

Comments

@e82eric
Copy link
Contributor

e82eric commented Apr 4, 2024

Windows Terminal version

67ae9f6

Windows build number

No response

Other Software

No response

Steps to reproduce

When a command that is the same length as the window is run, it causes the cursor to jump to the next line 2 characters into typing the next command.

  • When the final character is input the cursor moves back one char instead of to the next line.
  • It seems to vary by font size. I was able to reproduce the issue with font size 10 and 12 but not 11

Commenting out these 4 line seemed to fix the issue.

  • I tried to understand the unit tests mentioned in the ticket from the comments GH#15602 and tried to reproduce them in vim but was not successful
    // TODO: A row should not be marked as wrapped just because we wrote the last column.
    // It should be marked whenever we write _past_ it (above, _DoLineFeed call). See GH#15602.
    if (wrapAtEOL && state.columnEnd >= state.columnLimit)
    {
    textBuffer.SetWrapForced(cursorPosition.y, true);
    }

Expected Behavior

The cursor not to jump to the next line while typing the next command.

Actual Behavior

The cursor jumped to the next line while typing the next command

LineWidth_EdgeCase

@e82eric e82eric added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Apr 4, 2024
@j4james
Copy link
Collaborator

j4james commented Apr 4, 2024

This is a conpty issue - it doesn't occur in conhost/openconsole. What's meant to be happening is the cursor should move to the next line when you type a character on the last column of the page. Powershell actually makes a SetConsoleCursorPosition call to move it there - that just doesn't get translated correctly by conpty.

I think it may have to do with the vtengine's understanding of the WasWrapForced flag. We're using that to determine the lineWrapped state here:

// Calculate if two things are true:
// 1. this row wrapped
// 2. We're painting the last col of the row.
// In that case, set lineWrapped=true for the _PaintBufferOutputHelper call.
const auto lineWrapped = (buffer.GetRowByOffset(bufferLine.Origin().y).WasWrapForced()) &&
(bufferLine.RightExclusive() == buffer.GetSize().Width());

Which in turn sets the _wrappedRow property here:

// GH#4415, GH#5181
// If the renderer told us that this was a wrapped line, then mark
// that we've wrapped this line. The next time we attempt to move the
// cursor, if we're trying to move it to the start of the next line,
// we'll remember that this line was wrapped, and not manually break the
// line.
if (lineWrapped)
{
_wrappedRow = coord.y;
_trace.TraceSetWrapped(coord.y);
}

Which concludes with us determining that the line was already wrapped by the text output, so there is no need to move the cursor.

// If the previous line wrapped, then the cursor is already at this
// position, we just don't know it yet. Don't emit anything.
auto previousLineWrapped = false;
if (_wrappedRow.has_value())
{
previousLineWrapped = coord.y == _wrappedRow.value() + 1;
}

But in this case the conpty client hasn't wrapped, because of the VT delayed wrap functionality, so we do need to emit something to force it onto the next line.

This problem can be fixed just by removing the above code, but I'm not sure if there are legitimate cases where we actually do need to avoid a cursor movement here. However, I think it's possible that this code may have been mistakenly introduced to compensate for the fact that the original Windows Terminal VT interpreter didn't handle delayed wrap correctly. Since that's been fixed, this may no longer be necessary. I'm not positive about that though.

@j4james
Copy link
Collaborator

j4james commented Apr 4, 2024

@e82eric I forgot to add that the code you pointed out is also incorrect, and commenting it out will solve the problem in your particular case (i.e. when using powershell), but the underlying bug in the vtengine can still be triggered in other ways. For example, the cmd shell uses the legacy console API to write its output, and that doesn't pass through AdaptDispatch, but it does legitimately set the WasWrapForced flag, and will fail in a similar way.

@e82eric
Copy link
Contributor Author

e82eric commented Apr 5, 2024

@j4james thank you! that makes sense. Feel free to close this issue. (I had noticed it and wanted to see if I could sort out what was going on).

I tried commenting this out, and it did fix the issue, it does look like it has a side affect where when the window is resized the cursor moved and another line was added (I guess that is why those lines are needed).

// If the previous line wrapped, then the cursor is already at this
// position, we just don't know it yet. Don't emit anything.
auto previousLineWrapped = false;
if (_wrappedRow.has_value())
{
previousLineWrapped = coord.y == _wrappedRow.value() + 1;
}

resize

@j4james
Copy link
Collaborator

j4james commented Apr 7, 2024

@j4james thank you! that makes sense. Feel free to close this issue. (I had noticed it and wanted to see if I could sort out what was going on).

I think it may be worth keeping this open, because there's definitely a bug here which is independent of issue #15602, and I don't think it's tracked anywhere else.

I tried commenting this out, and it did fix the issue, it does look like it has a side affect where when the window is resized the cursor moved and another line was added

I haven't checked what exactly is going on there, but it's possible that's just a bug in the powershell readline implementation, and it only appears to be working correctly now because of the conpty bug.

@e82eric
Copy link
Contributor Author

e82eric commented Apr 8, 2024

@j4james sounds good. I ran a time travel trace to see if I could find anything on why it did the weird jump with those lines commented out. It looked like it called Cursor::SetPosition twice. Once after Terminal::Reflow to x:12, y:5 and once from VirtualTerminal::StateMachine::ProcessString x:43 y:4 from .[m.[2;44H (I think windbg mangled the .[m. part).

Maybe a combination of Terminal::Reflow moving to line 3 and then something with PSReadLine moving it back to the correct line with a weird x offset.

0:003> k
 # Child-SP          RetAddr               Call Site
00 00000054`e11fae90 00007ff9`214faee0     Microsoft_Terminal_Control!Cursor::SetPosition+0x1b [C:\Users\eric\src\terminal_line_end\src\buffer\out\cursor.cpp @ 200] 
01 00000054`e11faec0 00007ff9`213fd398     Microsoft_Terminal_Control!TextBuffer::Reflow+0xa80 [C:\Users\eric\src\terminal_line_end\src\buffer\out\textBuffer.cpp @ 2995] 
02 00000054`e11fb400 00007ff9`217530ef     Microsoft_Terminal_Control!Microsoft::Terminal::Core::Terminal::UserResize+0x448 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalCore\Terminal.cpp @ 301] 
03 00000054`e11fc020 00007ff9`2174570d     Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::ControlCore::_refreshSizeUnderLock+0x53f [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\ControlCore.cpp @ 1124] 
04 00000054`e11fc260 00007ff9`217454d5     Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::ControlCore::SizeOrScaleChanged+0x18d [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\ControlCore.cpp @ 1168] 
05 00000054`e11fc300 00007ff9`218058ff     Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::ControlCore::SizeChanged+0x45 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\ControlCore.cpp @ 1135] 
06 00000054`e11fc330 00007ff9`219ed6ba     Microsoft_Terminal_Control!winrt::impl::produce<winrt::Microsoft::Terminal::Control::implementation::ControlCore,winrt::Microsoft::Terminal::Control::IControlCore>::SizeChanged+0xff [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\Generated Files\winrt\Microsoft.Terminal.Control.h @ 2836] 
07 00000054`e11fc3e0 00007ff9`21924ec0     Microsoft_Terminal_Control!winrt::impl::consume_Microsoft_Terminal_Control_IControlCore<winrt::Microsoft::Terminal::Control::IControlCore>::SizeChanged+0xea [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\Generated Files\winrt\Microsoft.Terminal.Control.h @ 304] 
08 00000054`e11fc490 00007ff9`21a7fc7d     Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::TermControl::_SwapChainSizeChanged+0xa0 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\TermControl.cpp @ 2065] 
09 00000054`e11fc500 00007ff9`21aa49d6     Microsoft_Terminal_Control!`winrt::Microsoft::Terminal::Control::implementation::TermControlT<winrt::Microsoft::Terminal::Control::implementation::TermControl>::Connect'::`25'::<lambda_30>::operator()+0xbd [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\Generated Files\TermControl.xaml.g.hpp @ 354] 
0a 00000054`e11fc590 00007ff9`f5b070fc     Microsoft_Terminal_Control!winrt::impl::delegate<winrt::Windows::UI::Xaml::SizeChangedEventHandler,`winrt::Microsoft::Terminal::Control::implementation::TermControlT<winrt::Microsoft::Terminal::Control::implementation::TermControl>::Connect'::`25'::<lambda_30> >::Invoke+0x46 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\Generated Files\winrt\Windows.UI.Xaml.h @ 4683] 
0b 00000054`e11fc600 00007ff9`f5b06ef2     Windows_UI_Xaml!DirectUI::CRoutedEventSourceBase<DirectUI::IUntypedEventSource,Windows::UI::Xaml::ISizeChangedEventHandler,IInspectable,Windows::UI::Xaml::ISizeChangedEventArgs>::Raise+0xe8 [onecoreuap\windows\dxaml\xcp\dxaml\lib\JoltClasses.h @ 1041] 
0c 00000054`e11fc6a0 00007ff9`f5b0550a     Windows_UI_Xaml!DirectUI::FrameworkElement::OnSizeChanged+0x3a [onecoreuap\windows\dxaml\xcp\dxaml\lib\frameworkelement_partial.cpp @ 1096] 
0d 00000054`e11fc6d0 00007ff9`f5b0e805     Windows_UI_Xaml!DirectUI::DXamlCore::RaiseEvent+0x1ba [onecoreuap\windows\dxaml\xcp\dxaml\lib\dxamlcore.cpp @ 2027] 
0e (Inline Function) --------`--------     Windows_UI_Xaml!AgCoreCallbacks::RaiseEvent+0x22 [onecoreuap\windows\dxaml\xcp\dxaml\lib\fxcallbacks.cpp @ 100] 
0f (Inline Function) --------`--------     Windows_UI_Xaml!CFxCallbacks::JoltHelper_RaiseEvent+0x22 [onecoreuap\windows\dxaml\xcp\dxaml\lib\fxcallbacks.cpp @ 1018] 
10 00000054`e11fc770 00007ff9`f5c1fb95     Windows_UI_Xaml!CLayoutManager::RaiseSizeChangedEvents+0x1c9 [onecoreuap\windows\dxaml\xcp\core\layout\layoutmanager.cpp @ 472] 
11 00000054`e11fc980 00007ff9`f5c1ec00     Windows_UI_Xaml!CLayoutManager::UpdateLayout+0x2a5 [onecoreuap\windows\dxaml\xcp\core\layout\layoutmanager.cpp @ 338] 
12 00000054`e11fca10 00007ff9`f5b8bc6d     Windows_UI_Xaml!CCoreServices::NWDrawTree+0x330 [onecoreuap\windows\dxaml\xcp\core\dll\xcpcore.cpp @ 6294] 
13 00000054`e11fcb30 00007ff9`f5b8ba6f     Windows_UI_Xaml!CCoreServices::NWDrawMainTree+0xad [onecoreuap\windows\dxaml\xcp\core\dll\xcpcore.cpp @ 6084] 
14 00000054`e11fcb90 00007ff9`f5b8b996     Windows_UI_Xaml!CWindowRenderTarget::Draw+0x6f [onecoreuap\windows\dxaml\xcp\core\compositor\windowrendertarget.cpp @ 136] 
15 00000054`e11fcbd0 00007ff9`f5b7306d     Windows_UI_Xaml!CXcpBrowserHost::OnTick+0x96 [onecoreuap\windows\dxaml\xcp\host\win\browserdesktop\winbrowserhost.cpp @ 545] 
16 00000054`e11fcc30 00007ff9`f5b72f76     Windows_UI_Xaml!CXcpDispatcher::Tick+0x8d [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 1449] 
17 00000054`e11fcc70 00007ff9`f5ab58d9     Windows_UI_Xaml!CXcpDispatcher::OnReentrancyProtectedWindowMessage+0x42 [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 1041] 
18 (Inline Function) --------`--------     Windows_UI_Xaml!CXcpDispatcher::ProcessMessage+0xc5 [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 890] 
19 00000054`e11fccb0 00007ff9`f5ab794b     Windows_UI_Xaml!CXcpDispatcher::WindowProc+0x119 [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 839] 
1a 00000054`e11fcd00 00007ff9`f5ab783c     Windows_UI_Xaml!CDeferredInvoke::DispatchQueuedMessage+0xcb [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 301] 
1b (Inline Function) --------`--------     Windows_UI_Xaml!CXcpDispatcher::MessageTimerCallback+0x13 [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 1534] 
1c 00000054`e11fcd50 00007ff9`fdcd529b     Windows_UI_Xaml!CXcpDispatcher::MessageTimerCallbackStatic+0x1c [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 1526] 
1d 00000054`e11fcd80 00007ff9`fdcfc3ab     CoreMessaging!Microsoft__CoreUI__Dispatch__TimeoutHandler$CallbackThunk+0x11b
1e 00000054`e11fce00 00007ff9`fdcd9d84     CoreMessaging!Microsoft::CoreUI::Dispatch::TimeoutManager::Callback_OnDispatch+0x18b
1f 00000054`e11fce90 00007ff9`fdcd8d36     CoreMessaging!Microsoft::CoreUI::Dispatch::EventLoop::Callback_RunCoreLoop+0xc04
20 00000054`e11fcfb0 00007ff9`fdcd6f71     CoreMessaging!Microsoft::CoreUI::Dispatch::UserAdapter::OnUserDispatch+0x1d6
21 00000054`e11fd0a0 00007ff9`fdcd6d9c     CoreMessaging!Microsoft::CoreUI::Dispatch::UserAdapter_DoWork+0xf1
22 00000054`e11fd180 00007ffa`02dbef75     CoreMessaging!Microsoft::CoreUI::Dispatch::UserAdapter_WindowProc+0xfc
23 00000054`e11fd200 00007ffa`02dbe8dc     user32!UserCallWinProcCheckWow+0x515
24 00000054`e11fd390 00007ffa`02dd1223     user32!DispatchClientMessage+0x9c
25 00000054`e11fd3f0 00007ffa`031b0e64     user32!_fnDWORD+0x33
26 00000054`e11fd450 00007ffa`007c1124     ntdll!KiUserCallbackDispatcherContinue
27 000001ad`4c4b0820 00000000`000d0404     win32u!NtUserMessageCall+0x14
28 000001ad`4c4b0828 00000000`00050820     0xd0404
29 000001ad`4c4b0830 80000700`50020458     0x50820
2a 000001ad`4c4b0838 14cf0000`20280900     0x80000700`50020458
2b 000001ad`4c4b0840 00007ff6`dd560000     0x14cf0000`20280900
2c 000001ad`4c4b0848 00000000`00000000     WindowsTerminal!ILT+0(??YDNameQEAAAEAV0AEBV0Z) <PERF> (WindowsTerminal+0x0)
0:003> dx cPosition
cPosition                 : {X: 12, Y: 5} [Type: til::point]
    [+0x000] x                : 12 [Type: int]
    [+0x004] y                : 5 [Type: int]




0:003> k
 # Child-SP          RetAddr               Call Site
00 00000054`e11fae90 00007ff9`214faee0     Microsoft_Terminal_Control!Cursor::SetPosition+0x1b [C:\Users\eric\src\terminal_line_end\src\buffer\out\cursor.cpp @ 200] 
01 00000054`e11faec0 00007ff9`213fd398     Microsoft_Terminal_Control!TextBuffer::Reflow+0xa80 [C:\Users\eric\src\terminal_line_end\src\buffer\out\textBuffer.cpp @ 2995] 
02 00000054`e11fb400 00007ff9`217530ef     Microsoft_Terminal_Control!Microsoft::Terminal::Core::Terminal::UserResize+0x448 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalCore\Terminal.cpp @ 301] 
03 00000054`e11fc020 00007ff9`2174570d     Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::ControlCore::_refreshSizeUnderLock+0x53f [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\ControlCore.cpp @ 1124] 
04 00000054`e11fc260 00007ff9`217454d5     Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::ControlCore::SizeOrScaleChanged+0x18d [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\ControlCore.cpp @ 1168] 
05 00000054`e11fc300 00007ff9`218058ff     Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::ControlCore::SizeChanged+0x45 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\ControlCore.cpp @ 1135] 
06 00000054`e11fc330 00007ff9`219ed6ba     Microsoft_Terminal_Control!winrt::impl::produce<winrt::Microsoft::Terminal::Control::implementation::ControlCore,winrt::Microsoft::Terminal::Control::IControlCore>::SizeChanged+0xff [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\Generated Files\winrt\Microsoft.Terminal.Control.h @ 2836] 
07 00000054`e11fc3e0 00007ff9`21924ec0     Microsoft_Terminal_Control!winrt::impl::consume_Microsoft_Terminal_Control_IControlCore<winrt::Microsoft::Terminal::Control::IControlCore>::SizeChanged+0xea [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\Generated Files\winrt\Microsoft.Terminal.Control.h @ 304] 
08 00000054`e11fc490 00007ff9`21a7fc7d     Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::TermControl::_SwapChainSizeChanged+0xa0 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\TermControl.cpp @ 2065] 
09 00000054`e11fc500 00007ff9`21aa49d6     Microsoft_Terminal_Control!`winrt::Microsoft::Terminal::Control::implementation::TermControlT<winrt::Microsoft::Terminal::Control::implementation::TermControl>::Connect'::`25'::<lambda_30>::operator()+0xbd [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\Generated Files\TermControl.xaml.g.hpp @ 354] 
0a 00000054`e11fc590 00007ff9`f5b070fc     Microsoft_Terminal_Control!winrt::impl::delegate<winrt::Windows::UI::Xaml::SizeChangedEventHandler,`winrt::Microsoft::Terminal::Control::implementation::TermControlT<winrt::Microsoft::Terminal::Control::implementation::TermControl>::Connect'::`25'::<lambda_30> >::Invoke+0x46 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\Generated Files\winrt\Windows.UI.Xaml.h @ 4683] 
0b 00000054`e11fc600 00007ff9`f5b06ef2     Windows_UI_Xaml!DirectUI::CRoutedEventSourceBase<DirectUI::IUntypedEventSource,Windows::UI::Xaml::ISizeChangedEventHandler,IInspectable,Windows::UI::Xaml::ISizeChangedEventArgs>::Raise+0xe8 [onecoreuap\windows\dxaml\xcp\dxaml\lib\JoltClasses.h @ 1041] 
0c 00000054`e11fc6a0 00007ff9`f5b0550a     Windows_UI_Xaml!DirectUI::FrameworkElement::OnSizeChanged+0x3a [onecoreuap\windows\dxaml\xcp\dxaml\lib\frameworkelement_partial.cpp @ 1096] 
0d 00000054`e11fc6d0 00007ff9`f5b0e805     Windows_UI_Xaml!DirectUI::DXamlCore::RaiseEvent+0x1ba [onecoreuap\windows\dxaml\xcp\dxaml\lib\dxamlcore.cpp @ 2027] 
0e (Inline Function) --------`--------     Windows_UI_Xaml!AgCoreCallbacks::RaiseEvent+0x22 [onecoreuap\windows\dxaml\xcp\dxaml\lib\fxcallbacks.cpp @ 100] 
0f (Inline Function) --------`--------     Windows_UI_Xaml!CFxCallbacks::JoltHelper_RaiseEvent+0x22 [onecoreuap\windows\dxaml\xcp\dxaml\lib\fxcallbacks.cpp @ 1018] 
10 00000054`e11fc770 00007ff9`f5c1fb95     Windows_UI_Xaml!CLayoutManager::RaiseSizeChangedEvents+0x1c9 [onecoreuap\windows\dxaml\xcp\core\layout\layoutmanager.cpp @ 472] 
11 00000054`e11fc980 00007ff9`f5c1ec00     Windows_UI_Xaml!CLayoutManager::UpdateLayout+0x2a5 [onecoreuap\windows\dxaml\xcp\core\layout\layoutmanager.cpp @ 338] 
12 00000054`e11fca10 00007ff9`f5b8bc6d     Windows_UI_Xaml!CCoreServices::NWDrawTree+0x330 [onecoreuap\windows\dxaml\xcp\core\dll\xcpcore.cpp @ 6294] 
13 00000054`e11fcb30 00007ff9`f5b8ba6f     Windows_UI_Xaml!CCoreServices::NWDrawMainTree+0xad [onecoreuap\windows\dxaml\xcp\core\dll\xcpcore.cpp @ 6084] 
14 00000054`e11fcb90 00007ff9`f5b8b996     Windows_UI_Xaml!CWindowRenderTarget::Draw+0x6f [onecoreuap\windows\dxaml\xcp\core\compositor\windowrendertarget.cpp @ 136] 
15 00000054`e11fcbd0 00007ff9`f5b7306d     Windows_UI_Xaml!CXcpBrowserHost::OnTick+0x96 [onecoreuap\windows\dxaml\xcp\host\win\browserdesktop\winbrowserhost.cpp @ 545] 
16 00000054`e11fcc30 00007ff9`f5b72f76     Windows_UI_Xaml!CXcpDispatcher::Tick+0x8d [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 1449] 
17 00000054`e11fcc70 00007ff9`f5ab58d9     Windows_UI_Xaml!CXcpDispatcher::OnReentrancyProtectedWindowMessage+0x42 [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 1041] 
18 (Inline Function) --------`--------     Windows_UI_Xaml!CXcpDispatcher::ProcessMessage+0xc5 [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 890] 
19 00000054`e11fccb0 00007ff9`f5ab794b     Windows_UI_Xaml!CXcpDispatcher::WindowProc+0x119 [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 839] 
1a 00000054`e11fcd00 00007ff9`f5ab783c     Windows_UI_Xaml!CDeferredInvoke::DispatchQueuedMessage+0xcb [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 301] 
1b (Inline Function) --------`--------     Windows_UI_Xaml!CXcpDispatcher::MessageTimerCallback+0x13 [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 1534] 
1c 00000054`e11fcd50 00007ff9`fdcd529b     Windows_UI_Xaml!CXcpDispatcher::MessageTimerCallbackStatic+0x1c [onecoreuap\windows\dxaml\xcp\win\shared\xcpwindow.cpp @ 1526] 
1d 00000054`e11fcd80 00007ff9`fdcfc3ab     CoreMessaging!Microsoft__CoreUI__Dispatch__TimeoutHandler$CallbackThunk+0x11b
1e 00000054`e11fce00 00007ff9`fdcd9d84     CoreMessaging!Microsoft::CoreUI::Dispatch::TimeoutManager::Callback_OnDispatch+0x18b
1f 00000054`e11fce90 00007ff9`fdcd8d36     CoreMessaging!Microsoft::CoreUI::Dispatch::EventLoop::Callback_RunCoreLoop+0xc04
20 00000054`e11fcfb0 00007ff9`fdcd6f71     CoreMessaging!Microsoft::CoreUI::Dispatch::UserAdapter::OnUserDispatch+0x1d6
21 00000054`e11fd0a0 00007ff9`fdcd6d9c     CoreMessaging!Microsoft::CoreUI::Dispatch::UserAdapter_DoWork+0xf1
22 00000054`e11fd180 00007ffa`02dbef75     CoreMessaging!Microsoft::CoreUI::Dispatch::UserAdapter_WindowProc+0xfc
23 00000054`e11fd200 00007ffa`02dbe8dc     user32!UserCallWinProcCheckWow+0x515
24 00000054`e11fd390 00007ffa`02dd1223     user32!DispatchClientMessage+0x9c
25 00000054`e11fd3f0 00007ffa`031b0e64     user32!_fnDWORD+0x33
26 00000054`e11fd450 00007ffa`007c1124     ntdll!KiUserCallbackDispatcherContinue
27 000001ad`4c4b0820 00000000`000d0404     win32u!NtUserMessageCall+0x14
28 000001ad`4c4b0828 00000000`00050820     0xd0404
29 000001ad`4c4b0830 80000700`50020458     0x50820
2a 000001ad`4c4b0838 14cf0000`20280900     0x80000700`50020458
2b 000001ad`4c4b0840 00007ff6`dd560000     0x14cf0000`20280900
2c 000001ad`4c4b0848 00000000`00000000     WindowsTerminal!ILT+0(??YDNameQEAAAEAV0AEBV0Z) <PERF> (WindowsTerminal+0x0)
0:003> dx cPosition
cPosition                 : {X: 12, Y: 5} [Type: til::point]
    [+0x000] x                : 12 [Type: int]
    [+0x004] y                : 5 [Type: int]
0:003> g
Breakpoint 2 hit
Time Travel Position: 690A:3BA
Microsoft_Terminal_Control!Microsoft::Console::VirtualTerminal::StateMachine::ProcessString+0x4a:
00007ff9`215fedaa 48c744242000000000 mov   qword ptr [rsp+20h],0 ss:00000054`e1f5ef50=cccccccccccccccc
0:007> k
 # Child-SP          RetAddr               Call Site
00 00000054`e1f5ef30 00007ff9`213fbcf0     Microsoft_Terminal_Control!Microsoft::Console::VirtualTerminal::StateMachine::ProcessString+0x4a [C:\Users\eric\src\terminal_line_end\src\terminal\parser\stateMachine.cpp @ 2089] 
01 00000054`e1f5f170 00007ff9`21754999     Microsoft_Terminal_Control!Microsoft::Terminal::Core::Terminal::Write+0xe0 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalCore\Terminal.cpp @ 427] 
02 00000054`e1f5f270 00007ff9`217e611d     Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::ControlCore::_connectionOutputHandler+0x139 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\ControlCore.cpp @ 2055] 
03 00000054`e1f5f410 00007ff9`94a2d9f3     Microsoft_Terminal_Control!winrt::impl::delegate<winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler,`winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler::implementation<winrt::Microsoft::Terminal::Control::implementation::ControlCore,void (__cdecl winrt::Microsoft::Terminal::Control::implementation::ControlCore::*)(winrt::hstring const &)>'::`1'::<lambda_304_> >::Invoke+0x7d [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\Generated Files\winrt\Microsoft.Terminal.TerminalConnection.h @ 186] 
04 00000054`e1f5f480 00007ff9`949ff403     TerminalConnection!winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler::operator()+0xd3 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalConnection\Generated Files\winrt\Microsoft.Terminal.TerminalConnection.h @ 478] 
05 00000054`e1f5f530 00007ff9`949e20ab     TerminalConnection!winrt::impl::invoke<winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler,std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >+0x43 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalConnection\Generated Files\winrt\base.h @ 5890] 
06 00000054`e1f5f5d0 00007ff9`94a7b0cf     TerminalConnection!winrt::event<winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler>::operator()<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >+0x17b [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalConnection\Generated Files\winrt\base.h @ 6043] 
07 00000054`e1f5f770 00007ff9`94a7b773     TerminalConnection!winrt::Microsoft::Terminal::TerminalConnection::implementation::ConptyConnection::_OutputThread+0x76f [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalConnection\ConptyConnection.cpp @ 668] 
08 00000054`e1f5fa70 00007ffa`02937344     TerminalConnection!`winrt::Microsoft::Terminal::TerminalConnection::implementation::ConptyConnection::Start'::`3'::<lambda_1>::<lambda_invoker_cdecl>+0x33 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalConnection\ConptyConnection.cpp @ 386] 
09 00000054`e1f5fac0 00007ffa`031626b1     KERNEL32!BaseThreadInitThunk+0x14
0a 00000054`e1f5faf0 00000000`00000000     ntdll!RtlUserThreadStart+0x21
0:007> dx string
string                 : 0x54e1f5f1f0 : ".[m.[2;44H" [Type: std::basic_string_view<wchar_t,std::char_traits<wchar_t> > *]
    [<Raw View>]     [Type: std::basic_string_view<wchar_t,std::char_traits<wchar_t> >]
    [size]           : 0xa [Type: unsigned __int64]
    [0]              : 27 [Type: wchar_t]
    [1]              : 91 '[' [Type: wchar_t]
    [2]              : 109 'm' [Type: wchar_t]
    [3]              : 27 [Type: wchar_t]
    [4]              : 91 '[' [Type: wchar_t]
    [5]              : 50 '2' [Type: wchar_t]
    [6]              : 59 ';' [Type: wchar_t]
    [7]              : 52 '4' [Type: wchar_t]
    [8]              : 52 '4' [Type: wchar_t]
    [9]              : 72 'H' [Type: wchar_t]


0:007> g
Breakpoint 1 hit
Time Travel Position: 690F:333
Microsoft_Terminal_Control!Cursor::SetPosition+0x1b:
00007ff9`214ee68b 488b4c2430      mov     rcx,qword ptr [rsp+30h] ss:00000054`e1f5c4c0=000001ad5aa7ebd0
0:007> k
 # Child-SP          RetAddr               Call Site
00 00000054`e1f5c490 00007ff9`216422f1     Microsoft_Terminal_Control!Cursor::SetPosition+0x1b [C:\Users\eric\src\terminal_line_end\src\buffer\out\cursor.cpp @ 200] 
01 00000054`e1f5c4c0 00007ff9`21634ca9     Microsoft_Terminal_Control!Microsoft::Console::VirtualTerminal::AdaptDispatch::_CursorMovePosition+0x761 [C:\Users\eric\src\terminal_line_end\src\terminal\adapter\adaptDispatch.cpp @ 412] 
02 00000054`e1f5c710 00007ff9`2160cf70     Microsoft_Terminal_Control!Microsoft::Console::VirtualTerminal::AdaptDispatch::CursorPosition+0x89 [C:\Users\eric\src\terminal_line_end\src\terminal\adapter\adaptDispatch.cpp @ 490] 
03 00000054`e1f5c780 00007ff9`21603ace     Microsoft_Terminal_Control!Microsoft::Console::VirtualTerminal::OutputStateMachineEngine::ActionCsiDispatch+0x1300 [C:\Users\eric\src\terminal_line_end\src\terminal\parser\OutputStateMachineEngine.cpp @ 476] 
04 00000054`e1f5e9e0 00007ff9`21606ffc     Microsoft_Terminal_Control!`Microsoft::Console::VirtualTerminal::StateMachine::_ActionCsiDispatch'::`2'::<lambda_1>::operator()+0x37e [C:\Users\eric\src\terminal_line_end\src\terminal\parser\stateMachine.cpp @ 474] 
05 00000054`e1f5ecf0 00007ff9`21600013     Microsoft_Terminal_Control!Microsoft::Console::VirtualTerminal::StateMachine::_SafeExecute<`Microsoft::Console::VirtualTerminal::StateMachine::_ActionCsiDispatch'::`2'::<lambda_1> >+0x2c [C:\Users\eric\src\terminal_line_end\src\terminal\parser\stateMachine.cpp @ 2261] 
06 00000054`e1f5ee10 00007ff9`21601b28     Microsoft_Terminal_Control!Microsoft::Console::VirtualTerminal::StateMachine::_ActionCsiDispatch+0x63 [C:\Users\eric\src\terminal_line_end\src\terminal\parser\stateMachine.cpp @ 471] 
07 00000054`e1f5ee60 00007ff9`215fec18     Microsoft_Terminal_Control!Microsoft::Console::VirtualTerminal::StateMachine::_EventCsiParam+0x268 [C:\Users\eric\src\terminal_line_end\src\terminal\parser\stateMachine.cpp @ 1378] 
08 00000054`e1f5eec0 00007ff9`215ff041     Microsoft_Terminal_Control!Microsoft::Console::VirtualTerminal::StateMachine::ProcessCharacter+0x288 [C:\Users\eric\src\terminal_line_end\src\terminal\parser\stateMachine.cpp @ 1891] 
09 00000054`e1f5ef30 00007ff9`213fbcf0     Microsoft_Terminal_Control!Microsoft::Console::VirtualTerminal::StateMachine::ProcessString+0x2e1 [C:\Users\eric\src\terminal_line_end\src\terminal\parser\stateMachine.cpp @ 2131] 
0a 00000054`e1f5f170 00007ff9`21754999     Microsoft_Terminal_Control!Microsoft::Terminal::Core::Terminal::Write+0xe0 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalCore\Terminal.cpp @ 427] 
0b 00000054`e1f5f270 00007ff9`217e611d     Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::ControlCore::_connectionOutputHandler+0x139 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\ControlCore.cpp @ 2055] 
0c 00000054`e1f5f410 00007ff9`94a2d9f3     Microsoft_Terminal_Control!winrt::impl::delegate<winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler,`winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler::implementation<winrt::Microsoft::Terminal::Control::implementation::ControlCore,void (__cdecl winrt::Microsoft::Terminal::Control::implementation::ControlCore::*)(winrt::hstring const &)>'::`1'::<lambda_304_> >::Invoke+0x7d [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalControl\Generated Files\winrt\Microsoft.Terminal.TerminalConnection.h @ 186] 
0d 00000054`e1f5f480 00007ff9`949ff403     TerminalConnection!winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler::operator()+0xd3 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalConnection\Generated Files\winrt\Microsoft.Terminal.TerminalConnection.h @ 478] 
0e 00000054`e1f5f530 00007ff9`949e20ab     TerminalConnection!winrt::impl::invoke<winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler,std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >+0x43 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalConnection\Generated Files\winrt\base.h @ 5890] 
0f 00000054`e1f5f5d0 00007ff9`94a7b0cf     TerminalConnection!winrt::event<winrt::Microsoft::Terminal::TerminalConnection::TerminalOutputHandler>::operator()<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >+0x17b [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalConnection\Generated Files\winrt\base.h @ 6043] 
10 00000054`e1f5f770 00007ff9`94a7b773     TerminalConnection!winrt::Microsoft::Terminal::TerminalConnection::implementation::ConptyConnection::_OutputThread+0x76f [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalConnection\ConptyConnection.cpp @ 668] 
11 00000054`e1f5fa70 00007ffa`02937344     TerminalConnection!`winrt::Microsoft::Terminal::TerminalConnection::implementation::ConptyConnection::Start'::`3'::<lambda_1>::<lambda_invoker_cdecl>+0x33 [C:\Users\eric\src\terminal_line_end\src\cascadia\TerminalConnection\ConptyConnection.cpp @ 386] 
12 00000054`e1f5fac0 00007ffa`031626b1     KERNEL32!BaseThreadInitThunk+0x14
13 00000054`e1f5faf0 00000000`00000000     ntdll!RtlUserThreadStart+0x21
0:007> dx cPosition
cPosition                 : {X: 43, Y: 4} [Type: til::point]
    [+0x000] x                : 43 [Type: int]
    [+0x004] y                : 4 [Type: int]
` ``

@carlos-zamora carlos-zamora added Product-Conpty For console issues specifically related to conpty Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Apr 10, 2024
@carlos-zamora carlos-zamora added this to the Backlog milestone Apr 10, 2024
@carlos-zamora carlos-zamora added the Priority-3 A description (P3) label Apr 10, 2024
github-merge-queue bot pushed a commit that referenced this issue May 30, 2024
## Summary of the Pull Request

If the VT render engine is moving the cursor to the start of a row, and
the previous row was marked as wrapped, it will assume that it doesn't
need to do anything, because the next output should automatically move
the cursor to the correct position anyway.

However, if that cursor movement is coming from the final `PaintCursor`
call for the frame, there isn't going to be any more output, so the
cursor will be left in the wrong position.

This PR fixes that issue by clearing the `_wrappedRow` field before the
`_MoveCursor` call in the `PaintCursor` method.

## Validation Steps Performed

I've confirmed that this fixes all the test cases mentioned in issue
#17270, and issue #17013, and I've added a unit test to check the new
behavior is working as expected.

However, this change does break a couple of `ConptyRoundtripTests` that
were expecting the terminal row to be marked as wrapped when writing a
wrapped line in two parts using `WriteCharsLegacy`. This is because the
legacy way of wrapping a line isn't the same as a VT delayed wrap, so it
has to be emulated with cursor movement, and that can end up resetting
the wrap flag.

It's possible that could be fixed, but it's already broken in a number
of other ways, so I don't think this makes things much worse. For now,
I've just made the affected test cases skip the wrapping check.

## PR Checklist
- [x] Closes #17013
- [x] Closes #17270
- [x] Tests added/passed
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Tag-Fix Doesn't match tag requirements label May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Priority-3 A description (P3) Product-Conpty For console issues specifically related to conpty
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants