Pad/internal/editor
Greg Pomerantz c79c142397 editor: fix whole-file shaper leak + LineIndex mismatch (Phase 3)
Root cause of the ~1GB 'Unknown' memory on large files: with word wrap
on (the default), VisibleByteRange used the previously-shaped
GlyphLayout.VisualLineStarts to bound the visible byte range. That layout
only covers the visible window (~50 lines), not the whole document, so
whenever the viewport's line count exceeded the window's visual-line count
the range fell back to end=fileLen. The text shaper then laid out the ENTIRE
file each frame; its internal line/glyph buffers grow to the largest layout
ever shaped and are never released (document.reset() keeps the backing cap),
so memory ballooned to the file size (~1.1 GB for 10 MB) and OOM-killed the
process under scroll.

Fix: always derive the visible range from the real-line LineIndex (or the
heuristic estimate before it is ready). Word wrap needs no separate path:
each real line yields >= 1 visual line, so shaping viewportHeight/lineHeight
real lines always fills the viewport, and the range can never collapse to the
whole file.

Also fixed the pre-existing LineIndex storage mismatch: EditorLayout read
TheState.Editor.LineIndex (never set; SetLineIndex had zero callers) for
maxScroll and scrollByteOffset, so it always used the huge pre-index estimate.
It now reads cb.LineIndex, the single source of truth; the dead
EditorState.LineIndex field and SetLineIndex are removed.

On-device (emulator/SwiftShader), a 10 MB file now uses ~150 MB PSS / ~230 MB
RSS at steady state and stays flat under scroll (was 1.13 GB PSS / 1.5 GB RSS,
growing, OOM-killed). go test -race ./... green.
2026-08-16 12:16:52 -04:00
..
auto_save_test.go Fix test build after NewLogic signature change; add development plan draft 2026-08-15 22:18:04 -04:00
buffer_test.go fix(editor): wire key events to cursor movement 2026-06-03 07:41:18 -04:00
chunked_buffer_test.go editor: fix viewport-on-open, chunked-buffer drift, add size guard (Phase 3 code) 2026-08-16 10:35:10 -04:00
chunked_buffer.go editor: fix whole-file shaper leak + LineIndex mismatch (Phase 3) 2026-08-16 12:16:52 -04:00
cursor_test.go fix: update tests and fix SetCursorFromPoint panic 2026-06-04 07:24:44 -04:00
deterministic_file.go feat: virtual scrolling with chunked buffer for large files 2026-06-05 09:11:32 -04:00
e2e_test.go editor: fix viewport-on-open, chunked-buffer drift, add size guard (Phase 3 code) 2026-08-16 10:35:10 -04:00
filename_test.go feat: implement atomic writes for filesystem backend 2026-06-04 18:01:51 -04:00
frame.go Make state single-owner and stabilize race detector 2026-08-16 01:32:27 -04:00
ime_range_test.go editor: fix viewport-on-open, chunked-buffer drift, add size guard (Phase 3 code) 2026-08-16 10:35:10 -04:00
integration_test.go editor+ui: complete Android IME wiring (SelectionCmd, SnippetCmd, InputHintOp) 2026-08-16 02:43:58 -04:00
logic.go editor: fix viewport-on-open, chunked-buffer drift, add size guard (Phase 3 code) 2026-08-16 10:35:10 -04:00
mock_setup.go Integrate real filesystem with interface abstraction 2026-06-04 16:19:38 -04:00
scroll_fix_test.go WIP baseline: Termux open-file bridge + word-wrap-aware viewport/scroll 2026-08-16 00:31:26 -04:00
state.go editor: fix whole-file shaper leak + LineIndex mismatch (Phase 3) 2026-08-16 12:16:52 -04:00