Repository: microsoft/terminal (language: cpp)

Issue:
Passthrough mode's input handling appears to have regressed
### Windows Terminal version

Commit 6ffc3dc7a8a58c9961625618484cab431954e999

### Windows build number

10.0.19041.1415

### Other Software

_No response_

### Steps to reproduce

1. Enable the experimental `passthroughMode` opton.
2. Open a WSL bash shell (although I think all shells are similarly affected).
3. Start typing.

### Expected Behavior

Something reasonably normal.

### Actual Behavior

After every keypress the cursor position jumps forward several characters.

I thought at first that this was because passthrough  mode was still a work in progress, since the first time I got to test it it was already broken, but I've since gone back to the revision where it was first added, and it was working fine at that point. It looks to me like I broke it in PR #12703, although I'm not yet sure how.


Discussion / hints:

Fix patch:
diff --git a/src/host/getset.cpp b/src/host/getset.cpp
index e9057d12693..0b3356242ca 100644
--- a/src/host/getset.cpp
+++ b/src/host/getset.cpp
@@ -719,6 +719,10 @@ void ApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& cont
                                     position.Y < 0));
         // clang-format on
 
+        // MSFT: 15813316 - Try to use this SetCursorPosition call to inherit the cursor position.
+        auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
+        RETURN_IF_FAILED(gci.GetVtIo()->SetCursorPosition(position));
+
         RETURN_IF_NTSTATUS_FAILED(buffer.SetCursorPosition(position, true));
 
         LOG_IF_FAILED(ConsoleImeResizeCompStrView());
diff --git a/src/terminal/adapter/InteractDispatch.cpp b/src/terminal/adapter/InteractDispatch.cpp
index 6c205d3508b..8da0f121a54 100644
--- a/src/terminal/adapter/InteractDispatch.cpp
+++ b/src/terminal/adapter/InteractDispatch.cpp
@@ -150,15 +150,10 @@ bool InteractDispatch::MoveCursor(const VTInt row, const VTInt col)
 
     const auto coordCursorShort = til::unwrap_coord(coordCursor);
 
-    // MSFT: 15813316 - Try to use this MoveCursor call to inherit the cursor position.
-    auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
-    RETURN_IF_FAILED(gci.GetVtIo()->SetCursorPosition(coordCursorShort));
-
     // Finally, attempt to set the adjusted cursor position back into the console.
-    auto& cursor = _api.GetTextBuffer().GetCursor();
-    cursor.SetPosition(coordCursorShort);
-    cursor.SetHasMoved(true);
-    return true;
+    const auto api = gsl::not_null{ ServiceLocator::LocateGlobals().api };
+    auto& info = ServiceLocator::LocateGlobals().getConsoleInformation().GetActiveOutputBuffer();
+    return SUCCEEDED(api->SetConsoleCursorPositionImpl(info, coordCursorShort));
 }
 
 // Routine Description:


Test patch: