-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
A minor TSF refactoring #17067
A minor TSF refactoring #17067
Conversation
i dunno though, is fixing 11 issues in one PR enough to be considered "minor"? this is a trivial refactoring at best 😝 |
You're a champion, @lhecker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the PR is deleted files and deleting references to the deleted stuff, so that's nice.
The most complicated part is src/tsf/Implementation.cpp, but a good amount of the complexity there is that it's a lot of COM.
That said, looks great!
.columnLimit = buffer.GetRowByOffset(line.top).GetReadableColumnCount(), | ||
}; | ||
|
||
state.text = text.substr(0, _pData->activeComposition.cursorPos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.columnLimit = buffer.GetRowByOffset(line.top).GetReadableColumnCount(), | |
}; | |
state.text = text.substr(0, _pData->activeComposition.cursorPos); | |
.columnLimit = buffer.GetRowByOffset(line.top).GetReadableColumnCount(), | |
.text = text.substr(0, _pData->activeComposition.cursorPos), | |
}; |
Curious, any particular reason you didn't initialize it here with columnLimit
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it so that the two ReplaceText()
calls look somewhat symmetric. I felt like it's easier to read/understand that way.
@@ -195,9 +270,6 @@ try | |||
// 2. Paint Rows of Text | |||
_PaintBufferOutput(pEngine); | |||
|
|||
// 3. Paint overlays that reside above the text buffer | |||
_PaintOverlays(pEngine); | |||
|
|||
// 4. Paint Selection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 4. Paint Selection | |
// 3. Paint Selection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and update the other numbers below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not changing this code right now, because I'd like to remove it in the near-ish term and changing it now would only disturb the git blame
until then IMHO.
@@ -1003,9 +998,6 @@ DWORD WINAPI ConsoleInputThreadProcWin32(LPVOID /*lpParameter*/) | |||
// -- END LOAD BEARING CODE | |||
} | |||
|
|||
// Free all resources used by this thread | |||
DeactivateTextServices(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there any resources we need to free in the new code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, yes. However, this code is currently effectively unreachable, because we TerminateProcess
in the ServiceLocator
on shutdown. A better location for shutting down TSF is in the destructor of Window
but I figured it's fine if we just don't. After all, we also got the delete renderer
calls commented out there.
Next in the popular series of minor refactorings:
Out with the old, in with the new!
This PR removes all of the existing TSF code, both for conhost and
Windows Terminal. conhost's TSF implementation was awful:
It allocated an entire text buffer per line of input.
Additionally, its implementation spanned a whopping 40 files and
almost 5000 lines of code. Windows Terminal's implementation was
absolutely fine in comparison, but it was user unfriendly due to
two reasons: Its usage of the
CoreTextServices
WinRT API indirectlymeant that it used a non-transitory TSF document, which is not the
right choice for a terminal. A
TF_SS_TRANSITORY
document (-context)indicates to TSF that it cannot undo a previously completed composition
which is exactly what we need: Once composition has completed we send
the result to the shell and we cannot undo this later on.
The WinRT API does not allow us to use
TF_SS_TRANSITORY
and so it'sunsuitable for our application. Additionally, the implementation used
XAML to render the composition instead of being part of our text
renderer, which resulted in the text looking weird and hard to read.
The new implementation spans just 8 files and is ~1000 lines which
should make it significantly easier to maintain. The architecture is
not particularly great, but it's certainly better than what we had.
The implementation is almost entirely identical between both conhost
and Windows Terminal and thus they both also behave identical.
It fixes an uncountable number of subtle bugs in the conhost TSF
implementation, as it failed to check for status codes after calls.
It also adds several new features, like support for wavy underlines
(as used by the Japanese IME), dashed underlines (the default for
various languages now, like Vietnamese), colored underlines,
colored foreground/background controlled by the IME, and more!
I have tried to replicate the following issues and have a high
confidence that they're resolved now:
Closes #1304
Closes #3730
Closes #4052
Closes #5007 (as it is not applicable anymore)
Closes #5110
Closes #6186
Closes #6192
Closes #13805
Closes #14349
Closes #14407
Closes #16180
For the following issues I'm not entirely sure if it'll fix it,
but I suspect it's somewhat likely:
#13681
#16305
#16817
Lastly, there's one remaining bug that I don't know how to resolve.
However, that issue also plagues conhost and Windows Terminal
right now, so it's at least not a regression:
This will open the emoji picker at the old window location.
It also occurs when the cursor moves within the window.
While this is super annoying, I could not find a way to fix it.
Validation Steps Performed
Results in "xin chào" ✅
Toggles between the last 2 modes ✅
doubly underlined ✅
This results in "한한" ✅
Opens a popup which allows you to navigate with Arrow/Tab keys ✅