Skip to content

Commit 5c06ff4

Browse files
committed
Fix another VT input double-encoding issue
1 parent 6bf315a commit 5c06ff4

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/terminal/adapter/InteractDispatch.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,36 @@ void InteractDispatch::WriteString(const std::wstring_view string)
6262
{
6363
if (!string.empty())
6464
{
65-
const auto codepage = _api.GetOutputCodePage();
66-
InputEventQueue keyEvents;
67-
68-
for (const auto& wch : string)
65+
const auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
66+
const auto inputBuffer = gci.GetActiveInputBuffer();
67+
68+
// The input *may* be keyboard input in which case we must call CharToKeyEvents.
69+
//
70+
// However, it could also be legitimate VT sequences (escape keys, etc.).
71+
// If we called `InputBuffer::Write` with those, we would end up indirectly
72+
// calling `TerminalInput::HandleKey` and "double encode" the sequence.
73+
// The effect of this is noticeable with the German keyboard layout, for instance.
74+
//
75+
// It's worth noting that all of this is bad design in either case.
76+
// The way it should work is that we write INPUT_RECORDs and Strings as-is into the
77+
// InputBuffer, and only during retrieval they're converted into one or the other.
78+
// This prevents any kinds of double-encoding issues.
79+
if (inputBuffer->IsInVirtualTerminalInputMode())
6980
{
70-
CharToKeyEvents(wch, codepage, keyEvents);
81+
inputBuffer->WriteString(string);
7182
}
83+
else
84+
{
85+
const auto codepage = _api.GetOutputCodePage();
86+
InputEventQueue keyEvents;
7287

73-
WriteInput(keyEvents);
88+
for (const auto& wch : string)
89+
{
90+
CharToKeyEvents(wch, codepage, keyEvents);
91+
}
92+
93+
inputBuffer->Write(keyEvents);
94+
}
7495
}
7596
}
7697

0 commit comments

Comments
 (0)