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

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/12798
Author: @zadjii-msft
Created: 3/31/2022
Status: ✅ Merged
Merged: 3/31/2022
Merged by: @undefined

Base: main ← Head: dev/migrie/b/window-renamer-prototype-2


📝 Commits (6)

  • 90c7377 this seemingly works, but then auto-closes when you try opening it again once the window already has a name
  • c260409 This doesn't work at all
  • d7356a5 This is unbelievably stupid and I'm not at all surprised that this works
  • 6a76ea6 comment wtf is going on
  • 9469b93 more cleanup
  • 292af33 more comments

📊 Changes

4 files changed (+72 additions, -8 deletions)

View changed files

📝 src/cascadia/TerminalApp/AppActionHandlers.cpp (+42 -6)
📝 src/cascadia/TerminalApp/TerminalPage.cpp (+24 -2)
📝 src/cascadia/TerminalApp/TerminalPage.h (+5 -0)
📝 src/cascadia/TerminalApp/TerminalPage.xaml (+1 -0)

📄 Description

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


🔄 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/12798 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 3/31/2022 **Status:** ✅ Merged **Merged:** 3/31/2022 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/migrie/b/window-renamer-prototype-2` --- ### 📝 Commits (6) - [`90c7377`](https://github.com/microsoft/terminal/commit/90c7377a1dde09f15865cf0dfa9822753e7104cb) this seemingly works, but then auto-closes when you try opening it again once the window already has a name - [`c260409`](https://github.com/microsoft/terminal/commit/c2604094213d3dbbd2d4930659d4727da94787a4) This doesn't work at all - [`d7356a5`](https://github.com/microsoft/terminal/commit/d7356a578ef11bca1a3b1eb8c5ab1fbddba9a4d4) This is unbelievably stupid and I'm not at all surprised that this works - [`6a76ea6`](https://github.com/microsoft/terminal/commit/6a76ea6140215fee5b70547fb42b94cc02c6c2f9) comment wtf is going on - [`9469b93`](https://github.com/microsoft/terminal/commit/9469b9312aabbc43ec4ffbc5d2123bc1408d5568) more cleanup - [`292af33`](https://github.com/microsoft/terminal/commit/292af3363e37c408e60046ccf6ce92bd1728f700) more comments ### 📊 Changes **4 files changed** (+72 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalApp/AppActionHandlers.cpp` (+42 -6) 📝 `src/cascadia/TerminalApp/TerminalPage.cpp` (+24 -2) 📝 `src/cascadia/TerminalApp/TerminalPage.h` (+5 -0) 📝 `src/cascadia/TerminalApp/TerminalPage.xaml` (+1 -0) </details> ### 📄 Description 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 --- <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: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#29231