# \[Bug\]: Files surface jumps scroll focus and throws "Line doesn't exist" with word wrapping activated · Issue \#7907 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/issues/7907)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: backlog

Priority: 0

## Description

[Discussion and activity](https://git.cafe/pingdotgg/t3code/issues/7907)

---

### Before submitting

- [x] I searched existing issues and did not find a duplicate.
- [x] I included enough detail to reproduce or investigate the problem.

### Area

apps/web

### Steps to reproduce

1. Have "word wrap" activated in settings>apperance> word wrap at bottom 
2. Open a file with files surface in the right sidebar (with a lot of collapsable lines, less width => more lines collapsed)
3. Add more lines
4. Watch weird behavior with focus - Spamming enter will cause throwing an error

--- CLANKER DIAGNOSTIC BELOW (untested and personally not convinced at first glance, it could be a pierre/diffs issue) ---

The bug is a stale height calculation in the virtualized editor in `t3code>apps>web>src>components>files>FilePreviewPanel.tsx`.

When `wordWrap` is enabled:

1. A logical line can occupy several visual rows, especially at narrow widths.
2. Pressing Enter invalidates the virtualizer’s cached line heights.
3. Before the wrapped lines are measured again, the editor tries to reveal the caret and restore scroll.
4. It estimates positions using the default one-row `lineHeight`.
5. That estimate is too small, so the scroll jumps upward. The virtualizer may also recycle the focused DOM row, making the caret appear to disappear.

At wide widths, lines barely wrap, so the estimate is close enough and the bug is hidden. Disabling wrapping removes the variable-height layout entirely, which is why the problem disappears.

Short version: `Enter` exposes a race between editing, caret scrolling, and remeasuring wrapped virtualized lines.



### Expected behavior

Adding a line in a files surface should not mess up with focus and no error should be threw



### Actual behavior

Adding a line in a surface with a lot of wrapped lines will cause focus jumps and eventually it will cause throwing an error

### Impact

Minor bug or occasional failure

### Version or commit

0.0.34-nightly.20260820.1142

### Environment

CachyOS, desktop app

### Logs or stack traces

```shell
FileRenderer.processFileResult: Line doesnt exist
Error: FileRenderer.processFileResult: Line doesnt exist
    at be.processFileResult (t3code://app/assets/DiffCommentAnnotation-DQOJaIPV.js:1:7801)
    at be.renderFile (t3code://app/assets/DiffCommentAnnotation-DQOJaIPV.js:1:18824)
    at je.renderPreparedFile (t3code://app/assets/DiffCommentAnnotation-DQOJaIPV.js:1:41228)
    at je.renderPreparedFile (t3code://app/assets/DiffCommentAnnotation-DQOJaIPV.js:1:17214)
    at je.onRender (t3code://app/assets/DiffCommentAnnotation-DQOJaIPV.js:1:35788)
    at computeRenderRangeAndEmit (t3code://app/assets/index-DzSq6vN-.js:1886:73302)
    at fm (t3code://app/assets/index-DzSq6vN-.js:306:14489)
```

### Screenshots, recordings, or supporting files

[2026-08-22_10-19-13.mp4](https://github.com/user-attachments/assets/39e1e8c7-7369-488e-91cb-508e45db8672)

### Workaround

_No response_
