-
Notifications
You must be signed in to change notification settings - Fork 20
Case Study Picker Focus Bug
rtd edited this page Jan 12, 2026
·
1 revision
Type: DEBUG Skill: code-foundations → cc-developer-character → cc-quality-practices Method: Scientific Debugging
The picker window opens but the input field doesn't have focus.
Skill(code-foundations) → classifies as DEBUG
Skill(cc-developer-character) → "understand before fixing"
The skill enforced reading 369 lines of code before forming any hypothesis.
Instead of adding print statements or randomly trying fixes:
| Step | Action |
|---|---|
| Hypothesis | The focus code window?.contentView?.subviews.first { $0 is NSTextField } is finding the wrong text field |
| Reasoning | View hierarchy shows promptLabel (NSLabel) added before textField, and .first would match promptLabel |
| Verification | Grep confirmed NSLabel: NSTextField - so NSLabel is an NSTextField |
| Fix | Add focusInput() method on PickerWindow that directly references the correct textField |
Grep(pattern: "class NSLabel", output_mode: "content")
Found 1 match: class NSLabel: NSTextField { ... }
This took seconds but provided certainty. Without it, the fix would have been a guess.
| Without Skill | With Skill |
|---|---|
Tried makeFirstResponder multiple times |
Formed hypothesis first |
| Added delays, forced focus in lifecycle methods | Verified hypothesis before touching code |
| Searched for "second NSTextField" | Used existing textField reference |
| 10x longer debugging | Targeted fix in minutes |
Classify Task → Mindset Check → Read Code → Form Hypothesis → Verify → Fix
User: The issue is when the window pops up, the input box does not have focus.
Can we make sure it starts with focus?
Skill(code-foundations)
Successfully loaded skill
Task Classification: DEBUG - The picker window opens but the input box
doesn't have focus when it should.
Let me invoke the developer character skill first, then examine the code.
Skill(cc-developer-character)
Successfully loaded skill
Good. DEBUG task - I need to understand the code before fixing.
Read(grid-server/Sources/GridPicker/main.swift)
Read 369 lines
I can see the issue. Let me apply the Scientific Debugging Method.
Hypothesis: The focus code on line 346 is finding the wrong NSTextField.
Looking at the view hierarchy:
1. promptLabel (NSLabel, which extends NSTextField) - added first
2. textField (the actual editable input) - added second
3. closeButton - added third
The code `window?.contentView?.subviews.first { $0 is NSTextField }`
will find promptLabel first since NSLabel inherits from NSTextField.
Verification: Let me confirm NSLabel extends NSTextField.
Grep(pattern: "class NSLabel", path: "...", output_mode: "content")
Found 1 match: class NSLabel: NSTextField { ... }
Confirmed. NSLabel extends NSTextField on line 286, so `.first`
matches the prompt label, not the input field.
Fix: Add a method on PickerWindow to focus the input, since it
already has the textField reference. This avoids fragile subview searching.
Edit(grid-server/Sources/GridPicker/main.swift)
Added focusInput() method and updated caller
- Classification → Mindset → Understanding → Fix - The skill enforced this order
- Hypothesis-driven - "I think X is happening because Y" before touching code
- Verification - A quick grep confirmed the hypothesis with certainty
- Targeted fix - Used existing reference instead of fragile subview searching
Task Guides
Case Studies
- Picker History Review ⭐
- Comment Renumbering
- Critical Path Review
- Border Cleanup
- Picker Text Overflow
- Tab Indicator Removal
- Picker Focus Bug
- Window Picker Plan
Reference