-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Refactor TextBuffer::GenHTML #2038
Refactor TextBuffer::GenHTML #2038
Conversation
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.
This code looks much nicer and easier to comprehend! Thank you so much! Left a few comments throughout.
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 want to echo Carlos's request to file some issues for the todo's left in the code, but otherwise this looks substantially better than it was before. Good work!
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.
Sorry! I meant to mark "Request Changes" for the CSS issue. Otherwise it looks good!
@DHowett-MSFT, is there anything else you want to see here? I think the CSS thing was resolved and this is otherwise good to merge. |
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.
Thanks!
* Move Clipboard::GenHTML to TextBuffer (add params) Refactor RetrieveSelectedTextFromBuffer Modify CopyToClipboardEventArgs to include HTML data * minor code format fix * PR Changes NOTE: refactoring text buffer code is a separate task. New issue to be created. * Refactor TextBuffer::GenHTML (#2038) Fixes #1846. * nit change * x86 build fix * nit changes
🎉 Handy links: |
## Summary of the Pull Request When `GenHTML` or `GenRTF` encountered an empty line, they assumed that `CR` is the last character of the row and wrote it, even though in general `CR` and `LF` just break the line and instead of them either `<BR>` in HTML or `\line` in RTF is written. Don't know how I missed that in #2038. Another question is whether the `TextAndColor` structure which these methods receive and which is generated by `TextBuffer::GetTextForClipboard` should really contain `\r\n` at the end of each row. I think it'd be cleaner if it didn't esp. that afaik these last 2 characters don't have associated valid color information. ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [X] Closes #4187 * [X] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed - there aren't any related tests, right? * [ ] Requires documentation to be updated * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #4147 <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Copied various terminal states and verified the generated HTML.
## Summary of the Pull Request When `GenHTML` or `GenRTF` encountered an empty line, they assumed that `CR` is the last character of the row and wrote it, even though in general `CR` and `LF` just break the line and instead of them either `<BR>` in HTML or `\line` in RTF is written. Don't know how I missed that in #2038. Another question is whether the `TextAndColor` structure which these methods receive and which is generated by `TextBuffer::GetTextForClipboard` should really contain `\r\n` at the end of each row. I think it'd be cleaner if it didn't esp. that afaik these last 2 characters don't have associated valid color information. ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [X] Closes #4187 * [X] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed - there aren't any related tests, right? * [ ] Requires documentation to be updated * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #4147 <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Copied various terminal states and verified the generated HTML. (cherry picked from commit 1ca2912)
Summary of the Pull Request
Modernizes style of code in
TextBuffer::GenHTML
and significantly simplifies structure of produced HTML. There is sill scope for improvement (customization in particular) but that's another story.References
PR Checklist
GenHTML()
function #1846Detailed Description of the Pull Request / Additional comments
string
toostringstream
for string building.\r\n
to<BR>
in produced HTML.<span>
s with fg and bg color.Previous structure was.. weird. Each row was child span of previous row and there were empty spans with black color attributes in place of
\r\n
at end of the row. And all of this seemed unintended.<
. But it seems to accept the invalid HTML with>
from prompts. So if there is no text like<someTextThatNowBecomesATag>
, it should work.Problems/questions:
try
still needed?mc
to see it). Neither I and the function's author seemed to know how to fix this, becouse they (me at least) don't quite feel like HTML.