[PR #12637] [MERGED] Manually copy trailing attributes on a resize #29153

Open
opened 2026-01-31 09:33:09 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/12637
Author: @zadjii-msft
Created: 3/7/2022
Status: Merged
Merged: 3/21/2022
Merged by: @undefined

Base: mainHead: dev/migrie/b/32-attempt-2


📝 Commits (10+)

📊 Changes

5 files changed (+334 additions, -8 deletions)

View changed files

📝 build/pipelines/templates/build-console-steps.yml (+2 -0)
📝 src/buffer/out/textBuffer.cpp (+87 -6)
📝 src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp (+1 -1)
📝 src/host/screenInfo.cpp (+1 -1)
📝 src/host/ut_host/ScreenBufferTests.cpp (+243 -0)

📄 Description

THE WHITE WHALE

This is a fairly naive fix for this bug. It's not terribly performant,
but neither is resize in the first place.

When the buffer gets resized, typically we only copy the text up to the
MeasureRight point, the last printable char in the row. Then we'd just
use the last char's attributes to fill the remainder of the row.

Instead, this PR changes how reflow behaves when it gets to the end of
the row. After we finish copying text, then manually walk through the
attributes at the end of the row, and copy them over. This ensures that
cells that just have a colored space in them get copied into the new
buffer as well, and we don't just blat the last character's attributes
into the rest of the row. We'll do a similar thing once we get to the
last printable char in the buffer, copying the remaining attributes.

This could DEFINITELY be more performant. I think this current
implementation walks the attrs on every cell, then appends the new
attrs to the new ATTR_ROW. That could be optimized by just using the
actual iterator. The copy after the last printable char bit is also
especially bad in this regard. That could likely be a blind copy - I
just wanted to get this into the world.

Finally, we now copy the final attributes to the correct buffer: the new
one. We used to copy them to the old buffer, which we were about to
destroy.

Validation

I'll add more gifs in the morning, not enough time to finish spinning a
release Terminal build with this tonight.

Closes #32 🎉🎉🎉🎉🎉🎉🎉🎉🎉
Closes #12567


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/12637 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 3/7/2022 **Status:** ✅ Merged **Merged:** 3/21/2022 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/migrie/b/32-attempt-2` --- ### 📝 Commits (10+) - [`1f6210d`](https://github.com/microsoft/terminal/commit/1f6210dd92488d1a45f032813b3209445f70f0e1) I think this is a fix for #32 - [`966fa7b`](https://github.com/microsoft/terminal/commit/966fa7b042669a4b43f78527fa4f141ce87af766) another comment - [`65638cc`](https://github.com/microsoft/terminal/commit/65638cc1a3b5134d4d9fc3ed214a0d5dbd6c8c5d) cleanup, an edge case too - [`4388502`](https://github.com/microsoft/terminal/commit/43885020c3c38ce2f891adae8839dc2cb4103d72) wat - [`dba1e98`](https://github.com/microsoft/terminal/commit/dba1e985221f9a2fb36770dc5f66fa79f1d0d9d6) start working on a test - [`4e37693`](https://github.com/microsoft/terminal/commit/4e3769318c3f1fe87b3ec1162fa34536122e953e) okay I think the test is ready - [`37837ca`](https://github.com/microsoft/terminal/commit/37837cafbb69ed2612d6f485e021c2e5cbcbeddc) Fix persisting attrs below the last line of the buffer too - [`3e3d345`](https://github.com/microsoft/terminal/commit/3e3d345dadf687b1a40834382fd341c9e7029b2b) annother test - [`de062ab`](https://github.com/microsoft/terminal/commit/de062ab01096153bb8d93b2f1b04de4f1dbd3a93) another test - [`6843fc7`](https://github.com/microsoft/terminal/commit/6843fc7eb1b95031154559b5478d38417e605ab0) account for line rendition too ### 📊 Changes **5 files changed** (+334 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `build/pipelines/templates/build-console-steps.yml` (+2 -0) 📝 `src/buffer/out/textBuffer.cpp` (+87 -6) 📝 `src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp` (+1 -1) 📝 `src/host/screenInfo.cpp` (+1 -1) 📝 `src/host/ut_host/ScreenBufferTests.cpp` (+243 -0) </details> ### 📄 Description ## THE WHITE WHALE This is a fairly naive fix for this bug. It's not terribly performant, but neither is resize in the first place. When the buffer gets resized, typically we only copy the text up to the `MeasureRight` point, the last printable char in the row. Then we'd just use the last char's attributes to fill the remainder of the row. Instead, this PR changes how reflow behaves when it gets to the end of the row. After we finish copying text, then manually walk through the attributes at the end of the row, and copy them over. This ensures that cells that just have a colored space in them get copied into the new buffer as well, and we don't just blat the last character's attributes into the rest of the row. We'll do a similar thing once we get to the last printable char in the buffer, copying the remaining attributes. This could DEFINITELY be more performant. I think this current implementation walks the attrs _on every cell_, then appends the new attrs to the new ATTR_ROW. That could be optimized by just using the actual iterator. The copy after the last printable char bit is also especially bad in this regard. That could likely be a blind copy - I just wanted to get this into the world. Finally, we now copy the final attributes to the correct buffer: the new one. We used to copy them to the _old_ buffer, which we were about to destroy. ## Validation I'll add more gifs in the morning, not enough time to finish spinning a release Terminal build with this tonight. Closes #32 🎉🎉🎉🎉🎉🎉🎉🎉🎉 Closes #12567 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:33:09 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#29153