Commit 9ed86e9
authored
fix: retry giveFocus on next animation frame for newly created blocks (#3100)
Fixes #2926
## Problem
Keyboard scrolling (arrow keys) does not work in newly opened blocks
until the user mouse-clicks. This is a race condition in BlockFull's
focus handling.
When `isFocused` becomes true for a newly created block,
`setFocusTarget()` calls `viewModel.giveFocus()`. But the view's DOM
element (terminal, Monaco editor, webview) may not be mounted yet, so
`giveFocus()` returns false and focus falls back to the hidden dummy
`<input>` element — which cannot handle arrow key scrolling.
## Fix
After falling back to the dummy focus element, schedule a
`requestAnimationFrame` callback that retries `viewModel.giveFocus()`.
This gives React one more frame to flush pending renders and mount the
view's DOM, so focus transfers to the real element once it's ready.
## Test Plan
- Open a new terminal block — verify arrow keys scroll immediately
without clicking
- Open a file preview — verify arrow keys scroll the file content
- Open a webview — verify keyboard scrolling works
- Switch focus between blocks using keyboard shortcuts — verify
scrolling works in each
- `npx tsc --noEmit` passes clean
---------
Signed-off-by: majiayu000 <1835304752@qq.com>1 parent 4805c59 commit 9ed86e9
1 file changed
+19
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
| |||
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
159 | 168 | | |
160 | 169 | | |
161 | 170 | | |
| |||
221 | 230 | | |
222 | 231 | | |
223 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
224 | 237 | | |
225 | 238 | | |
226 | 239 | | |
227 | 240 | | |
228 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
229 | 248 | | |
230 | 249 | | |
231 | 250 | | |
| |||
0 commit comments