MCPcopy
hub / github.com/witheve/Eve / saveDocument

Method saveDocument

src/ide.ts:2239–2285  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2237 }
2238
2239 saveDocument() {
2240 if(!this.documentId || !this.loaded) return;
2241
2242 // When we try to edit a gist-backed file we need to fork it and save the new file to disk.
2243 // @FIXME: This is all terribly hacky, and needs to be cleaned up as part of the FileStore rework.
2244 if(this.documentId.indexOf("gist:") === 0) {
2245 let oldId = this.documentId;
2246
2247 let neueId = oldId.slice(5);
2248 neueId = neueId.slice(0, 7) + neueId.slice(32);
2249 neueId = `/root/${neueId}`;
2250
2251 if(this._fileCache[neueId]) {
2252 return this.promptOverwrite(neueId);
2253 } else {
2254 return this.cloneDocument(neueId);
2255 }
2256 }
2257
2258 let md = this.editor.toMarkdown();
2259 let isDirty = md !== this._fileCache[this.documentId];
2260
2261 // @NOTE: We sync this here to prevent a terrible reload bug that occurs when saving to the file system.
2262 // This isn't really the right fix, but it's a quick one that helps prevent lost work in trivial cases
2263 // like navigating the workspace.
2264 // @TODO: This logic needs ripped out entirely and replaced with a saner abstraction that keeps the
2265 // file system and workspace in sync.
2266 // @TODO: localStorage also needs to get synced and cleared lest it permanently overrule other sources of truth.
2267 this._fileCache[this.documentId] = md;
2268
2269 // if we're not local, we notify the outside world that we're trying
2270 // to save
2271 if(!this.local) {
2272 return this.onSaveDocument(this, this.documentId, md);
2273 }
2274
2275 // othewise, save it to local storage
2276 let saves = JSON.parse(localStorage.getItem("eve-saves") || "{}");
2277 if(isDirty) {
2278 saves[this.documentId] = md;
2279 this.modified = true;
2280 } else {
2281 this.modified = false;
2282 saves[this.documentId] = undefined;
2283 }
2284 localStorage.setItem("eve-saves", JSON.stringify(saves));
2285 }
2286
2287 revertDocument() {
2288 if(!this.documentId || !this.loaded) return;

Callers 2

IDEClass · 0.95
cloneDocumentMethod · 0.95

Calls 3

promptOverwriteMethod · 0.95
cloneDocumentMethod · 0.95
toMarkdownMethod · 0.80

Tested by

no test coverage detected