[PR #10336] [MERGED] Expose Text Attributes to UI Automation #27995

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/10336
Author: @carlos-zamora
Created: 6/4/2021
Status: Merged
Merged: 7/10/2021
Merged by: @undefined

Base: mainHead: dev/cazamor/a11y-7000/text-attributes


📝 Commits (10+)

  • 84bca57 Expose Text Attributes to UI Automation
  • 136a548 fix/add tests; remove invalid attributes
  • a7bbf9d address PR feedback
  • 2be632b remove 'limit' from new iterator
  • 84fdf5a bugfix: italic was not detected properly
  • 3fa8c95 fix 1 char wide case; better degenerate range handling; don't return lambda for attr verification
  • 7c88010 Merge branch 'main' into dev/cazamor/a11y-7000/text-attributes
  • 74a645f fix failing tests and audit mode
  • 2e7895c fix typo
  • 96a5551 apply Dustin's suggestions

📊 Changes

17 files changed (+866 additions, -46 deletions)

View changed files

📝 src/buffer/out/textBufferCellIterator.cpp (+5 -0)
📝 src/buffer/out/textBufferCellIterator.hpp (+2 -0)
📝 src/cascadia/TerminalControl/ControlCore.cpp (+2 -0)
📝 src/cascadia/TerminalControl/XamlUiaTextRange.cpp (+46 -4)
📝 src/cascadia/TerminalCore/Terminal.cpp (+0 -1)
📝 src/cascadia/TerminalCore/Terminal.hpp (+7 -1)
📝 src/cascadia/TerminalCore/terminalrenderdata.cpp (+6 -14)
📝 src/host/renderData.hpp (+1 -2)
📝 src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp (+294 -0)
📝 src/renderer/base/FontInfoBase.cpp (+1 -1)
📝 src/renderer/inc/FontInfoBase.hpp (+1 -1)
📝 src/renderer/inc/IRenderData.hpp (+0 -2)
📝 src/types/IBaseData.h (+1 -0)
📝 src/types/UiaTextRangeBase.cpp (+433 -13)
📝 src/types/UiaTextRangeBase.hpp (+5 -0)
📝 src/types/UiaTracing.cpp (+49 -5)
📝 src/types/UiaTracing.h (+13 -2)

📄 Description

Summary of the Pull Request

This implements GetAttributeValue and FindAttribute for UiaTextRangeBase (the shared ITextRangeProvider for Conhost and Windows Terminal). This also updates UiaTracing to collect more useful information on these function calls.

References

#7000 - Epic
Text Attribute Identifiers
ITextRangeProvider::GetAttributeValue
ITextRangeProvider::FindAttribute

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • TextBuffer:
    • Exposes a new TextBufferCellIterator that takes in an end position. This simplifies the logic drastically as we can now use this iterator to navigate through the text buffer. The iterator can also expose the position in the buffer.
  • UiaTextRangeBase:
    • Shared logic & helper functions:
      • Most of the text attributes are stored as TextAttributes in the text buffer. To extract them, we generate an attribute verification function via _getAttrVerificationFn(), then use that to verify if a given cell has the desired attribute.
      • A few attributes are special (i.e. font name, font size, and "is read only"), in that they are (1) acquired differently and (2) consistent across the entire text buffer. These are handled separate from the attribute verification function.
    • GetAttributeValue: Retrieve the attribute verification of the first cell in the range. Then, verify that the entire range has that attribute by iterating through the text range. If a cell does not have that attribute, return the "reserved mixed attribute value".
    • FindAttribute: Iterate through the text range and leverage the attribute verification function to find the first contiguous range with that attribute. Then, make the end exclusive and output a UiaTextRangeBase. This function must be able to perform a search backwards, so we abstract the "start" and "end" into resultFirstAnchor and resultSecondAnchor, then perform post processing to output a valid UiaTextRangeBase.
  • UiaTracing:
    • GetAttributeValue: Log uia text range, desired attribute, resulting attribute metadata, and the type of the result.
    • FindAttribute: Log uia text range, desired attribute and attribute metadata, if we were searching backwards, the type of the result, and the resulting text range.
    • AttributeType is a nice way to understand/record if the result was either of the reserved UIA values, a normal result, or an error.
  • UiaTextRangeTests:
    • GetAttributeValue:
      • verify that we know which attributes we support
      • test each of the known text attributes (expecting 100% code coverage for _getAttrVerificationFn())
    • FindAttribute:
      • test each of the known special text attributes
      • test IsItalic. NOTE: I'm explicitly only testing one of the standard text attributes because the logic is largely the same between all of them and they leverage _getAttrVerificationFn().

Validation Steps Performed

  • @codeofdusk has been testing this Conhost build
  • Tests added for Conhost and shared implementation
  • Windows Terminal changes were manually verified using accessibility insights and NVDA

🔄 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/10336 **Author:** [@carlos-zamora](https://github.com/carlos-zamora) **Created:** 6/4/2021 **Status:** ✅ Merged **Merged:** 7/10/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/cazamor/a11y-7000/text-attributes` --- ### 📝 Commits (10+) - [`84bca57`](https://github.com/microsoft/terminal/commit/84bca57d2dbd28d1a3b9b98182c50616f11e3136) Expose Text Attributes to UI Automation - [`136a548`](https://github.com/microsoft/terminal/commit/136a54898b6965fc060921602fc0ce4c7cf96c03) fix/add tests; remove invalid attributes - [`a7bbf9d`](https://github.com/microsoft/terminal/commit/a7bbf9d3de0b2f5133dc0e9b8421e31639a0ae14) address PR feedback - [`2be632b`](https://github.com/microsoft/terminal/commit/2be632bae85790840c9d95b9b9f6af01806108c2) remove 'limit' from new iterator - [`84fdf5a`](https://github.com/microsoft/terminal/commit/84fdf5add15d4dbf3a69229b09d0e790c76e4326) bugfix: italic was not detected properly - [`3fa8c95`](https://github.com/microsoft/terminal/commit/3fa8c95f639e814522ef398c02d2e7dd13ae284c) fix 1 char wide case; better degenerate range handling; don't return lambda for attr verification - [`7c88010`](https://github.com/microsoft/terminal/commit/7c88010f4cd0c1149ac2111373d3b80e60eeb8bb) Merge branch 'main' into dev/cazamor/a11y-7000/text-attributes - [`74a645f`](https://github.com/microsoft/terminal/commit/74a645f8fc853c27bbcadf1e8c916989f0326ec1) fix failing tests and audit mode - [`2e7895c`](https://github.com/microsoft/terminal/commit/2e7895c8456b4b9f02b0f1130f94b9710ea1ffac) fix typo - [`96a5551`](https://github.com/microsoft/terminal/commit/96a55511021905415c44dcbcfb4b705869416a1f) apply Dustin's suggestions ### 📊 Changes **17 files changed** (+866 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `src/buffer/out/textBufferCellIterator.cpp` (+5 -0) 📝 `src/buffer/out/textBufferCellIterator.hpp` (+2 -0) 📝 `src/cascadia/TerminalControl/ControlCore.cpp` (+2 -0) 📝 `src/cascadia/TerminalControl/XamlUiaTextRange.cpp` (+46 -4) 📝 `src/cascadia/TerminalCore/Terminal.cpp` (+0 -1) 📝 `src/cascadia/TerminalCore/Terminal.hpp` (+7 -1) 📝 `src/cascadia/TerminalCore/terminalrenderdata.cpp` (+6 -14) 📝 `src/host/renderData.hpp` (+1 -2) 📝 `src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp` (+294 -0) 📝 `src/renderer/base/FontInfoBase.cpp` (+1 -1) 📝 `src/renderer/inc/FontInfoBase.hpp` (+1 -1) 📝 `src/renderer/inc/IRenderData.hpp` (+0 -2) 📝 `src/types/IBaseData.h` (+1 -0) 📝 `src/types/UiaTextRangeBase.cpp` (+433 -13) 📝 `src/types/UiaTextRangeBase.hpp` (+5 -0) 📝 `src/types/UiaTracing.cpp` (+49 -5) 📝 `src/types/UiaTracing.h` (+13 -2) </details> ### 📄 Description ## Summary of the Pull Request This implements `GetAttributeValue` and `FindAttribute` for `UiaTextRangeBase` (the shared `ITextRangeProvider` for Conhost and Windows Terminal). This also updates `UiaTracing` to collect more useful information on these function calls. ## References #7000 - Epic [Text Attribute Identifiers](https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-textattribute-ids) [ITextRangeProvider::GetAttributeValue](https://docs.microsoft.com/en-us/windows/win32/api/uiautomationcore/nf-uiautomationcore-itextrangeprovider-getattributevalue) [ITextRangeProvider::FindAttribute](https://docs.microsoft.com/en-us/windows/win32/api/uiautomationcore/nf-uiautomationcore-itextrangeprovider-findattribute) ## PR Checklist * [X] Closes #2161 * [X] Tests added/passed ## Detailed Description of the Pull Request / Additional comments - `TextBuffer`: - Exposes a new `TextBufferCellIterator` that takes in an end position. This simplifies the logic drastically as we can now use this iterator to navigate through the text buffer. The iterator can also expose the position in the buffer. - `UiaTextRangeBase`: - Shared logic & helper functions: - Most of the text attributes are stored as `TextAttribute`s in the text buffer. To extract them, we generate an attribute verification function via `_getAttrVerificationFn()`, then use that to verify if a given cell has the desired attribute. - A few attributes are special (i.e. font name, font size, and "is read only"), in that they are (1) acquired differently and (2) consistent across the entire text buffer. These are handled separate from the attribute verification function. - `GetAttributeValue`: Retrieve the attribute verification of the first cell in the range. Then, verify that the entire range has that attribute by iterating through the text range. If a cell does not have that attribute, return the "reserved mixed attribute value". - `FindAttribute`: Iterate through the text range and leverage the attribute verification function to find the first contiguous range with that attribute. Then, make the end exclusive and output a `UiaTextRangeBase`. This function must be able to perform a search backwards, so we abstract the "start" and "end" into `resultFirstAnchor` and `resultSecondAnchor`, then perform post processing to output a valid `UiaTextRangeBase`. - `UiaTracing`: - `GetAttributeValue`: Log uia text range, desired attribute, resulting attribute metadata, and the type of the result. - `FindAttribute`: Log uia text range, desired attribute and attribute metadata, if we were searching backwards, the type of the result, and the resulting text range. - `AttributeType` is a nice way to understand/record if the result was either of the reserved UIA values, a normal result, or an error. - `UiaTextRangeTests`: - `GetAttributeValue`: - verify that we know which attributes we support - test each of the known text attributes (expecting 100% code coverage for `_getAttrVerificationFn()`) - `FindAttribute`: - test each of the known _special_ text attributes - test `IsItalic`. NOTE: I'm explicitly only testing one of the standard text attributes because the logic is largely the same between all of them and they leverage `_getAttrVerificationFn()`. ## Validation Steps Performed - @codeofdusk has been testing this Conhost build - Tests added for Conhost and shared implementation - Windows Terminal changes were manually verified using accessibility insights and NVDA --- <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:25:38 +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#27995