[PR #12798] Auto-focus window renamer textbox on open #29236

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

Original Pull Request: https://github.com/microsoft/terminal/pull/12798

State: closed
Merged: Yes


Does what it says on the tin. This is maximal BODGE.

TeachingTip doesn't provide an Opened event.
(https://github.com/microsoft/microsoft-ui-xaml/issues/1607). But we
want to focus the renamer text box when it's opened. We can't do that
immediately, the TextBox technically isn't in the visual tree yet. We
have to wait for it to get added some time after we call IsOpen. How do
we do that reliably? Usually, for this kind of thing, we'd just use a
one-off LayoutUpdated event, as a notification that the TextBox was
added to the tree. HOWEVER:

  • The first time this is fired, when the box is first opened,
    yeeting focus doesn't work on the first LayoutUpdated. It does work on
    the second LayoutUpdated. Okay, so we'll wait for two LayoutUpdated
    events, and focus on the second.
  • On subsequent opens: We only ever get a single LayoutUpdated. Period.
    But, you can successfully focus it on that LayoutUpdated.

So, we'll keep track of how many LayoutUpdated's we've ever gotten. If
we've had at least 2, then we can focus the text box.

We're also not using a ContentDialog for this, because in Xaml Islands a
text box in a ContentDialog won't receive any keypresses. Fun!

References

PR Checklist

  • Will close out #12021, but that's an a11y bug that needs secondary
    validation
  • Closes More cursor droppings (#11322)
  • I work here
  • Tests added/passed
  • [n/a] Requires documentation to be updated

Validation Steps Performed

Tested manually

**Original Pull Request:** https://github.com/microsoft/terminal/pull/12798 **State:** closed **Merged:** Yes --- Does what it says on the tin. This is maximal BODGE. `TeachingTip` doesn't provide an `Opened` event. (https://github.com/microsoft/microsoft-ui-xaml/issues/1607). But we want to focus the renamer text box when it's opened. We can't do that immediately, the TextBox technically isn't in the visual tree yet. We have to wait for it to get added some time after we call IsOpen. How do we do that reliably? Usually, for this kind of thing, we'd just use a one-off LayoutUpdated event, as a notification that the TextBox was added to the tree. HOWEVER: * The _first_ time this is fired, when the box is _first_ opened, yeeting focus doesn't work on the first LayoutUpdated. It does work on the second LayoutUpdated. Okay, so we'll wait for two LayoutUpdated events, and focus on the second. * On subsequent opens: We only ever get a single LayoutUpdated. Period. But, you can successfully focus it on that LayoutUpdated. So, we'll keep track of how many LayoutUpdated's we've _ever_ gotten. If we've had at least 2, then we can focus the text box. We're also not using a ContentDialog for this, because in Xaml Islands a text box in a ContentDialog won't receive _any_ keypresses. Fun! ## References * microsoft/microsoft-ui-xaml#1607 * microsoft/microsoft-ui-xaml#6910 * microsoft/microsoft-ui-xaml#3257 * microsoft/terminal#9662 ## PR Checklist * [x] Will close out #12021, but that's an a11y bug that needs secondary validation * [x] Closes #11322 * [x] I work here * [x] Tests added/passed * [n/a] Requires documentation to be updated ## Validation Steps Performed Tested manually
claunia added the pull-request label 2026-01-31 09:33:39 +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#29236