helix-editor/helix
View
A View is one open viewport into a Document. It owns the scroll position, the gutter offsets, the jumplist, and a reference to the document it shows. The view tree (the split layout) is composed of Views.
The implementation is in helix-view/src/view.rs (1,000 lines) and 1,000 lines).helix-view/src/tree.rs (
Identity
slotmap::new_key_type! {
pub struct ViewId;
}ViewId is a slotmap key. View IDs survive document reloads; closing a view invalidates the slot but doesn't reuse it for in-flight operations.
State on a View
| Field | Purpose |
|---|---|
id: ViewId |
Slot key. |
doc: DocumentId |
The document this view shows. |
area: Rect |
The screen area assigned by the layout tree. |
view_position: ViewPosition |
Scroll: anchor (char position at the top) + vertical_offset (visual rows scrolled). |
jumps: JumpList |
Bounded ring buffer of recent positions for Ctrl-i/Ctrl-o. |
last_modified_docs: [Option<DocumentId>; 2] |
Last two modified docs in this view; powers gm (goto last modified). |
last_accessed_doc: Option<DocumentId> |
Powers ga (goto last accessed). |
gutters: Vec<GutterType> |
Active gutters (line numbers, diagnostics, diff, breakpoints, spacer). |
How views relate to documents
- Many views, one doc. Two views can show the same document. Each has its own selection (stored on the document keyed by
ViewId), scroll, and gutters. - One view at a time is active.
Editor::tree.focuspicks the active view;current!(editor)returns(view, doc). - Closing a view does not close the doc.
:bc(buffer-close) removes the doc fromdocuments.
ViewPosition
pub struct ViewPosition {
pub anchor: usize, // char idx at top of viewport
pub horizontal_offset: usize, // chars scrolled left
pub vertical_offset: usize, // soft-wrap visual rows scrolled
}For non-soft-wrapped buffers, vertical_offset is always 0 and the viewport is described by the line containing anchor. With soft-wrap on, anchor may sit mid-line and vertical_offset indicates which visual row of that line is at the top.
align_view(doc, view, Align) (helix-view/src/lib.rs) recomputes ViewPosition so the cursor aligns to the top, center, or bottom of the viewport. The same logic is used by gz (sticky cursor).
Jumplist
Each view has its own jumplist. A jump is recorded:
- Before opening a file from a picker.
- Before
goto_definitionand similar commands. - Before any motion that crosses a "big gap" (e.g. paragraph jump, ctrl-d/u).
Ctrl-i and Ctrl-o walk the list. The JumpList (helix-view/src/view.rs) is bounded — older entries are evicted.
Gutters
The gutter strip on the left of a view is configured per-view (defaulting to the editor-wide setting). Built-in gutters (in helix-view/src/gutter.rs):
Diagnostics— error/warning/info/hint indicator.Diff—+,-,~signs fromhelix-vcs.LineNumbers— absolute or relative.Spacer— single-column padding.Breakpoints— DAP breakpoint dot and the active-frame arrow.
Each gutter declares a width (required_width) and a per-line render closure. View::gutter_offset returns the total width consumed by gutters, used to compute the inner text area.
The view tree
Tree (helix-view/src/tree.rs) is a binary tree of Containers and View leaves. Operations:
Tree::split(view, layout, action)— split the focused view;Layout::HorizontalorLayout::Vertical.Tree::remove(view_id)— close a view; rebalance the tree.Tree::traverse()— iterate views in display order.Tree::focus_next/focus_prev— directional focus changes.Tree::resize— adjust the area allocations.
The default split direction follows the user's last action; commands like Ctrl-w v and Ctrl-w s map to vertical/horizontal explicitly.
Per-view state on the document
Document keeps three things keyed by ViewId:
selections: HashMap<ViewId, Selection>view_data: HashMap<ViewId, ViewData>view_offset: HashMap<ViewId, ViewPosition>
These are pruned when a view closes via Document::remove_view.
See also
- primitives/document — what views display.
- packages/helix-view —
Tree, gutters,align_view. - packages/helix-term —
EditorView(the compositor layer that draws all views).
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.