JS: switch view, close without save, force reloading


#1

Questions about JS script:

  1. How to focus in the view of a specific open file (e.g. aaa.txt)?

  2. How to close an open file (with or without focus in it) without saving it?

  3. How to force reloading an open file? (Sometimes the automatic reloading action lags significantly.)

Thanks a lot!


#2
var views = require("ko/views").editors();
var view = null // if you want to do more with it later
for v of views{
// loop through list of views to find the one you want
    if (v.filepath == "aaa.txt"){
        view = v;
    }
}
view.scintilla.focus(); // 1.
// not sure why this is necessary but I can't dig further today, but now that you're focused on the view
var  view = require("ko/views").current().get()
view.reloadIfChanged() // 3. 
view.close(true); // 2. Close without asking to save

Those should do it.

  • Carey

#3

Hi @careyh It works. Thank you!