Close specific tab before opening Atom


#1

I pasted a large JSON file into Atom without thinking. Now on startup, Atom has that file open, and it gets stuck. I’ve already read ways to clear cache, however, I have some very important unsaved changes in another tab (I know, I should’ve saved, mea culpa). Is there any way for me to “delete” the giant JSON tab from Atom’s IndexedDB (as I understand, that’s where these unsaved files are stored) without deleting all my other open, unsaved tabs?

Thank you!


#2

You could potentially try using Atom 1.14.0-beta0, which has improvements regarding large file loading. It might be enough to get you up and running without manually fixing the storage.

I’m not aware if it’s possible to edit the data though in IndexedDB.


#3

This unfortunately did not do the trick. Updated to latest version of Atom, placed my backed up IndexedDB folder into the right place, and now it’s hanging again. There has got to be a way!


#4

Are you sure you installed the latest beta version (1.14.0) instead of the latest live version (1.13.0)? There are three different “latest versions”, so just saying that doesn’t tell us which one you’re using.


#5

Yes sir, 1.14.0 beta-0.

Currently experimenting with putting the IndexedDB folder into my own Electron project, opening up Dev Tools and editing the db via Application -> IndexedDB -> AtomEnvironments -> States. Not having much luck there, unfortunately, as I’m told that the problematic string is “too long to edit”. But at least I was able to get at the saved states, so maybe I just need the right editor!

e: SUCCESS! For posterity, my ugly, roundabout method for doing this:

  • Step 1: Create a new Electron project.

  • Step 2: Run Electron project such that it creates an entry in %APPDATA%/<project name>/IndexedDB.

  • Step 4: Delete folder file__0.indexeddb.leveldb from above directory.

  • Step 3: cd %APPDATA%/Atom/IndexedDB.

  • Step 4: Copy folder file__0.indexeddb.leveldb from above directory to %APPDATA%/<project name>/IndexedDB.

  • Step 5: Open Electron project, then open Inspect Tool, go to Application -> IndexedDB -> AtomEnvironments -> States.

  • Step 6: Locate your project’s latest saved state by looking at the storedAt value of the state. Take note of the key value associated with it (should start with string editor-).

  • Step 7: Locate your problematic tab. This can be done by looking at <your latest state>.value.project.buffers, that’s the list of saved tabs. Opening each buffer, you can look at the text value to find the problematic tab.

  • Step 8: Execute my ugly, ugly code in the inspect tool console:

      var db;
      function openDB() {
       var DBOpenRequest = window.indexedDB.open("AtomEnvironments");
       DBOpenRequest.onsuccess = function(e) {
         console.log(e);
         console.log('opened');
         db = DBOpenRequest.result;
         var request = db.transaction(['states'], 'readwrite')
           .objectStore('states')
           .get('<YOUR-KEY-FROM-STEP-6>')
         request.onsuccess = function(e){
           console.log('success getting key');
           console.log(e);
           console.log(request);
           var res = e.target.result;
           // Modify the value of the buffers to remove the specific buffer you need.
           // Mine was at the end of the array, so a .pop was enough.
           res.value.project.buffers.pop();
           console.log(res);
           var writing = db.transaction(['states'], 'readwrite')
             .objectStore('states')
             .put(res, '<YOUR-KEY-FROM-STEP-6>');
    
          writing.onsuccess = function(e){
            console.log('write successful');
            console.log(e);
          }
         }
       };
      }
    
  • Step 9: Copy %APPDATA%/<your project name>/IndexedDB/file__0.indexeddb.leveldb back into %APPDATA%/Atom/IndexedDB. Overwrite if necssary.

e: In retrospect, I could’ve avoided writing code by just copying the plaintext of the unsaved file right from the inspect tool. Oh well, it was a fun exercise ¯_(ツ)_/¯