Editable code: how should files larger than the retained-text budget be edited?

Open
#761 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
12/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Active
Tech stack
typescript, zig
Domain
desktop

Research direction

This is an open design question, not a bounded change. Start with the 384 KiB cap in examples/code-editor/src/document.ts and the selection reconciliation in src/runtime/canvas_widget_runtime.zig, where the runtime clamps the retained selection when source is rebuilt. Done would mean an agreed approach for keeping the caret's document position across windowed source replacement, which maintainers have not yet decided on.

Written by the indexing model from the issue text.

Description

I am building a text editor on Native SDK 0.11.0. Documents can exceed the per-view retained-text budget, and the docs and examples only describe a read-only preview for that case. Files of any size need to stay editable, so I need to know how those files are supposed to be edited. All references are to v0.11.0.

Current limits
  • Editable source is capped at 384 KiB in the official code-editor example (document.ts#L8). Larger files open read-only. codeEditable is false when the source is truncated (view.ts#L73), and the status shows "preview limited to 384 KiB" (editor.ts#L166).
  • Whole-file reads stop at 1 MiB and return truncated beyond that (files.mdx#L13). Cmd.readFileStream has no total-size ceiling (files.mdx#L44).
  • The per-view retained-text budget is 512 KiB (text.zig#L9).
What I tried

The native-ui skill recommends keeping a bounded window in the model and sliding it with on-scroll for large content (SKILL.md#L378). I applied that to an editable <code>:

<scroll value="{scrollTop}" on-scroll="scrolled">
  <column>
    <stack height="{topSpacerHeight}" />
    <code source="{editorText}" editable="true" on-input="edit" height="{stageHeight}" />
    <stack height="{bottomSpacerHeight}" />
  </column>
</scroll>

The spacers keep the scrollbar over the full document. The scroll handler replaces the rendered slice:

// The runtime owns the selection. Replacing `text` changes the source.
function scrolled(model: Model, state: ScrollState): Model {
  const firstLine = Math.floor(state.offsetY / LINE_HEIGHT);
  const text = sliceLines(model.document, firstLine, model.windowLines);
  return { ...model, scrollTop: firstLine * LINE_HEIGHT, editor: { ...model.editor, text } };
}
What I see

The window renders, but the caret does not follow the document. Click a line, then scroll until that line leaves the window. The automation snapshot reports the textbox selection collapsed at the edge of the new window, while the app's editor state still has the caret on the original line. Scrolling back restores the view, but the caret was painted at the window edge the whole time.

The runtime owns the selection and the app cannot provide one:

The runtime does not consult the app's TextEditState.selection. on-input carries selection changes only from the widget to the model (#213).

Questions
  • Is the 384 KiB preview limit a runtime boundary, or can an editable <code> go beyond it?
  • If a windowed source is the intended approach, how should the caret keep its document position across source replacement? #755 appears to target this and was closed without merging, as was #748.
  • Should large files be read with Cmd.readFileStream and kept in an app-owned window, or is another reading path intended for the editor?

Related: #461 (same gap at the Zig tier), #755, #748, #213, #506, #514.

Environment: Native SDK 0.11.0 (scriptc 0.3.0), macOS 27.0.1 (26A434, arm64), TypeScript core + native markup.

Dominant language
Zig
Stars
7.9k
Forks
335
Avg merge
10h 33m
Merged PRs (30d)
147

Getting set up

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.

More from vercel-labs/native

All issues in vercel-labs/native

Similar issues

More Desktop Dev issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.