Repository navigation
feat: read source code in a read-only CodeMirror view - #60
Merged
Merged
Conversation
Code files opened as plain prose: no highlighting, no line numbers, long lines wrapped. They now open in CodeMirror, read-only but selectable, with line numbers, folding, search and highlighting for the file's language. CodeMirror loads only when a code file is first opened, and each language only when a file in it is. The reader keeps its place and tells the assistant which lines are on screen, as the prose reader did. The Source view highlights any language the same way.
The code reader is enough on its own, so code files no longer open the Source editor beside it or keep drafts. A text reader may now leave out its source language to open read-only; the source editor is back as it was, and the language lookup by path lives in the code reader.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Source code opened in the prose reader. There was no highlighting and no line numbers, and long lines wrapped. Folder import (#58) makes reading code a main use, so code needs a proper reader.
What changes
features/reader/code-reader.tsx(new): a read-only CodeMirror view.basicSetupwithEditorState.readOnly. Line numbers, folding, Cmd/Ctrl+F search, and selection and copying all work.flowposition: line plus the share of it scrolled past. The place is restored when the file is shown, and survives content changes, for example after the agent rewrites the file.get_reader_stateviewport), the same way the prose reader does.React.lazyindocument-tabs.tsx, so CodeMirror stays out of the main bundle.@codemirror/language-datais imported dynamically and matches a language by file name. Each language is its own chunk, loaded when a file in it is opened.code-reader, andpython-*.jsetc. are separate chunks.core/files.ts:isCodePath..txtand.logstay prose.TextReaderDefinition.sourceLanguageis now optional. When it is absent,TextFileReaderrenders the reader directly instead ofTextDocumentWorkspace.read_active_sourceandedit_active_sourcedo not apply to code files. It reads them withreadand can rewrite them withwrite.SourceEditoris unchanged from main. The language lookup by path lives in the code reader.@codemirror/language-data, plus@codemirror/languageas a direct dependency because pnpm requires it for the import. The lockfile has a single version each of@codemirror/language,/stateand/view.Not in this PR
Dark theme, go-to-definition, a wrap toggle.
Tests
tools/run.pyshows the code in the reader. It isaria-readonly, and once Python loads,defis a highlighted token. There is no Source button.pnpm checkpasses.