Skip to content

Commit 26e4e4c

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

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/host/VtIo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ bool VtIo::IsUsingVt() const
187187
writer.WriteUTF8(
188188
"\x1b[c" // DA1 Report (Primary Device Attributes)
189189
"\x1b[?1004h" // Focus Event Mode
190-
"\x1b[?9001h" // Win32 Input Mode
190+
//"\x1b[?9001h" // Win32 Input Mode
191191
);
192192

193193
writer.Submit();

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)