The editor never loses or mangles your work (#16420)
What holds when you edit a file in the browser (/<owner>/<repo>/edit/<branch>/<path>) or in the terminal's workspace (e, then ctrl+s):
- Your file keeps its line endings. A browser sends a text box's line breaks as CRLF whatever the file had. The editor notes the file's own endings when it opens (
eol, by what most lines end in) and the save writes your text in them, so a one-line edit changes one line (asTyped,src/web/pages/edit.ts). The terminal's editor keeps the bytes it read. - A save never replaces a newer change unseen. The editor remembers which version of the file it opened. If someone changed it on that branch since, the save is refused: "notes.md changed on main since you opened it. Nothing was saved; your text is kept." The same check and the same sentence in both editors (
fileAtandEditFile.wasinsrc/actions/contents.ts,changedSinceWordsinsrc/actions/edit_words.ts).- On the web, the refusal links See what changed (the file's history on the branch) and offers Replace their change with mine beside a box, "I have seen their change, and mine should replace it". The button writes only with the box ticked, and only over the version you were shown; if a third change lands meanwhile, it refuses again. Plain Commit change keeps refusing. Their change stays in the history either way.
- In the terminal (
src/tui/screens/workspace.ts, its commit boxsrc/tui/screens/commit.ts), the commit box says the sentence and nothing is written; your buffer is untouched. The terminal has no Replace: to keep yours over theirs, paste your text into the web editor and use its Replace. - A new file is refused the same way when a file of that name appeared meanwhile.
- A reload does not lose what you typed. What you have typed and not committed is kept in this browser, per file, and comes back with one line: "Restored what you typed here before (time), not yet committed." with Discard it. It is dropped once the commit lands. Storage that is blocked or private keeps nothing and changes nothing else. It lives only in this browser (
editorJs,src/web/client.ts).- A restored draft brings back the commit message and description too. Typed against an earlier version of the file, it says so in the note, and Commit shows what changed first (the refusal above, once, with the text and message kept) (#16454).
- Replace waits for its tick. Replace their change with mine stays disabled until its box is ticked; with scripts off it stays enabled, and the server asks for the tick all the same (#16454).
- A reader who may not write is shown the way to propose. A reader (a contributor, say) opening the editor is told "You can't change owner/repo directly; fork it to propose a change", with the fork beside it (
cannotChangeWords,src/actions/edit_words.ts); the terminal's workspace says the same for a signed-in reader (src/tui/screens/workspace.ts). Someone who cannot read still gets the 404 a stranger gets (#16454).
Proof: test/web-editor-integrity.test.ts (endings, two tabs, Replace and its box, drafts; "a restored draft brings its commit message back, and says when it was typed against an earlier version", "Replace their change with mine waits for its tick"), test/web-editor.test.ts ("a reader who may not write is told how to propose, with the fork, never an editor"), test/tui-editor.test.ts (the terminal's refusal).