-
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
Add an efficient text stream write function #14821
Merged
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a6c5e7a
Add an efficient text stream write function
lhecker f8e6884
Address feedback, Simplify code
lhecker 3d04d37
Make spell-check happy
lhecker 99f19a9
Fix AuditMode failures
lhecker 173e916
Add CopyRangeFrom to later implement TextBuffer::Reflow
lhecker 5040328
Remove debug helpers
lhecker 17e3ca5
Fix AuditMode failures
lhecker f9fbb8a
Fix compilation
lhecker d1163b5
Simplify member naming scheme, Improve performance
lhecker 94fbb52
Fix cursor movement and attribute writing
lhecker 3c5c3d4
Merge remote-tracking branch 'origin/main' into dev/lhecker/8000-stre…
lhecker 934a06d
Fix unit tests
lhecker a99b9d6
Fix unit tests
lhecker 99e669a
Address feedback by j4james, Potentially fix exact line wrapping
lhecker db89261
Revert exact wrap, Remove unused code, Improve tests
lhecker e77f2be
Make the spelling-bot happy
lhecker 0ca2286
Make the spelling-bot happpier?
lhecker 4b070fd
Address feedback
lhecker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,49 +256,20 @@ class CommonState | |
std::unique_ptr<TextBuffer> m_backupTextBufferInfo; | ||
std::unique_ptr<INPUT_READ_HANDLE_DATA> m_readHandle; | ||
|
||
struct TestString | ||
{ | ||
std::wstring_view string; | ||
bool wide = false; | ||
}; | ||
|
||
static void applyTestString(ROW* pRow, const auto& testStrings) | ||
{ | ||
uint16_t x = 0; | ||
for (const auto& t : testStrings) | ||
{ | ||
if (t.wide) | ||
{ | ||
pRow->ReplaceCharacters(x, 2, t.string); | ||
x += 2; | ||
} | ||
else | ||
{ | ||
for (const auto& ch : t.string) | ||
{ | ||
pRow->ReplaceCharacters(x, 1, { &ch, 1 }); | ||
x += 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void FillRow(ROW* pRow, bool wrapForced) | ||
{ | ||
// fill a row | ||
// 9 characters, 6 spaces. 15 total | ||
// か = \x304b | ||
// き = \x304d | ||
|
||
static constexpr std::array testStrings{ | ||
TestString{ L"AB" }, | ||
TestString{ L"\x304b", true }, | ||
TestString{ L"C" }, | ||
TestString{ L"\x304d", true }, | ||
TestString{ L"DE " }, | ||
}; | ||
|
||
applyTestString(pRow, testStrings); | ||
uint16_t column = 0; | ||
for (const auto& ch : std::wstring_view{ L"AB\u304bC\u304dDE " }) | ||
{ | ||
const uint16_t width = ch >= 0x80 ? 2 : 1; | ||
pRow->ReplaceCharacters(column, width, { &ch, 1 }); | ||
column += width; | ||
} | ||
Comment on lines
+266
to
+272
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot why I made this change... But it's much shorter now, so there's that at least. |
||
|
||
// A = bright red on dark gray | ||
// This string starts at index 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
kinda weird that this is a static on textbuffer when it just does a
til::utf16_pop
, but presumably this does more in the future?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.
In the future I'll replace this function with some ICU code that actually advances the string by an entire grapheme cluster. So, if you have something like å ("a˚") it'll advance by 2 code points and not just 1 like it does now.
It's possible to just put the ICU code into
til
and use it throughout the code directly, just like we do it right now with the UTF-16 helpers. But from now on, I'd like to avoid doing that, even if it means writing suchstatic
methods, because I'd like to keep everything string handling related as close and tight as possible in the future. I thinkOutputCellIterator
had the same intention originally and was well meant, but it suffers from being a leaky abstraction. Lots of code is now built around an implicit assumption thatOutputCellIterator
will always advance by exactly 1 or 2 columns. Using thetil
UTF-16 helpers directly elsewhere in our code would have a similar effect in my opinion, because it would equally leak (and potentially incorrectly leak) any assumptions about howTextBuffer
handles incoming text under normal circumstances.