atom-archive / xray

An experimental next-generation Electron-based text editor
MIT License
8.48k stars 235 forks source link

Implement saving feature for buffers #84

Closed as-cii closed 6 years ago

as-cii commented 6 years ago

This pull request introduces a new SaveActiveBuffer command that is dispatched when either pressing S or CtrlS. This new command applies to both local and remote workspaces, which in the latter case issues a save request to the host owning the buffer.

The save routine is carried out on a separate thread thanks to the introduction of Buffer::snapshot, which builds a read-only Sendable clone of the current state of the buffer. Then, after successfully grabbing the file's lock in a background thread, the buffer's tree of visible fragments is traversed, encoded to UTF-8, and written to disk in a streaming fashion.

At some point in the future we should handle different encodings, as well as coping with file corruption in the presence of an error in a graceful way.