lapce / lapce/floem

editor view / scrollbar jumps up and down nonsensically

Open
#1,069 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
4.3k
Forks
218
PR merge metrics
No merged PRs in 30d

Description

Problem

Pressing Enter at the end of a wrapped multi-paragraph document causes the viewport to jump wildly instead of tracking the caret. The jump shrinks with each Enter and mostly stops once enough blank lines have been added.

Root cause: every edit calls check_cache_rev, which clears the entire text-layout cache. When the scroll container then calls ensure_visible to follow the caret, vline_of_rvline walks up from the caret line looking for cached layouts. With the cache empty, find_vline_of_line_backwards falls back to counting 1 visual line per line, undercounting every wrapped paragraph above the caret. The resulting caret rect is at the wrong y, and Scroll jumps to "fix" it. Because each Enter leaves the cache in a different partial state (different lines re-laid-out by compute_screen_lines), the wrong answer differs each time — hence the alternation. New blank lines don't wrap, so the undercount shrinks as they accumulate.

How to reproduce

Copy this report into the editor example, move the caret to the end of the text, and press enter multiple times. If you maximize the app, the problem won't manifest, because the whole document fits and no scrolling is needed.

Quick fix

In ensure_visible, eagerly materialize text layouts for lines 0..=caret_line before calling vline_of_rvline. That gives the vline walk real wrap counts instead of the 1-per-line fallback.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in ensure_visible and trace its interaction with vline_of_rvline, find_vline_of_line_backwards, and the text-layout cache cleared by check_cache_rev. Reproduce the issue in the editor example with a wrapped multi-paragraph document, then verify that repeated Enter presses keep the viewport tracking the caret instead of jumping.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.