Skip to content

fix(ui): keep background fold maintenance out of Normal mode - #568

Merged
sudo-tee merged 1 commit into
sudo-tee:mainfrom
jensenojs:fix/streaming-input-mode
Nov 16, 2026
Merged

sudo-tee merged 1 commit into
sudo-tee:mainfrom
jensenojs:fix/streaming-input-mode

Conversation

@jensenojs

@jensenojs jensenojs commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Fixes #567

IME composition and input state get interrupted while typing whenever the output window streams or scrolls.

Neovim has no API to delete manual folds , so async fold rebuilds ran :normal! zE / zd in the unfocused output window—flipping global mode to Normal mid-typing (noautocmd only hides the event; vim.on_key still observes z, E in Normal):

state.ui.output_folds        authoritative fold ranges
        | derive
        v
output window folds          window-local, rebuilt while user types
        |
        +-- old: :normal! zE / zd -> global State = Normal
        |                          -> ModeChanged i:n, attributed to output buf
        +-- new: foldmethod recompute / rebuild recorded ranges
                                   -> mode untouched

noautocmd hides the autocmd but the mode still changes; vim.on_key observes z, E in Normal during the call.

Change

Cost: clearing is O(rendered lines) instead of O(folds) — 1.65 µs per 1000 rendered lines. Not measurable in the default lazy window (0.19 vs 0.21 ms per fold change); fully expanded history at 70k lines is 1.98 vs 0.83 ms.

state.ui.output_folds        authoritative fold ranges
        | derive
        v
output window folds          window-local, rebuilt while user types
        |
        +-- old: :normal! zE / zd -> global State = Normal
        |                          -> ModeChanged i:n, attributed to output buf
        +-- new: foldmethod recompute / rebuild recorded ranges
                                   -> mode untouched

Folds are window-local, mode is global. Deriving folds for a background
window used to emit a mode change to listeners of the input window, which
is where the input source switch hangs. Clearing by foldmethod recompute
and repairing by rebuilding the recorded ranges keeps that derivation
inside the output window.

Cost: O(rendered lines) instead of O(folds); 1.65us per 1000 rendered
lines, unchanged in the default lazy window.

Tests: real-UI mode/key observers and a PTY streaming run wired into CI
assert no ModeChanged, no synthetic Normal keys, and that an intentional
<Esc> is still reported.

Fixes sudo-tee#567
@jensenojs
jensenojs marked this pull request as ready for review November 16, 2026 12:01
@sudo-tee

Copy link
Copy Markdown
Owner

Thanks for the fix

This seems like a reasonable approach

@sudo-tee
sudo-tee merged commit b796436 into sudo-tee:main Nov 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Background fold maintenance enters Normal mode while typing

2 participants