Tame your Pulsar (Atom) editor's tree view by making it obey the "Hidden On Startup" setting!
Go to file
DrMaxNix c3136aad4a 📄 update copyright year 2024-03-08 22:49:36 +01:00
.editorconfig 🔧 add editorconfig 2023-05-11 20:23:17 +02:00
LICENSE 📄 update copyright year 2024-03-08 22:49:36 +01:00
README.md 🐛 use default in case tree-view setting is unset 2024-03-08 22:49:30 +01:00
init-snippet.coffee 🐛 use default in case tree-view setting is unset 2024-03-08 22:49:30 +01:00
init-snippet.js 🐛 use default in case tree-view setting is unset 2024-03-08 22:49:30 +01:00

README.md

Tame Pulsar Tree View

Tame your Pulsar (Atom) editor's tree view by making it obey the "Hidden On Startup" setting!

Why?

It is a well-known bug that Atom, and its fork Pulsar, don't properly respect the Hidden On Startup setting of its tree view.

I have used a lot of bodge-fixes for this in the past, but every now and then they stopped working due to updates. With this repository I'm trying to maintain a working code snippet for Pulsar's init.coffee which will make the Hidden On Startup setting work the way it should.

Setup Instructions

Open your init script:

Edit > Init Script

When the file is called init.js, add this snippet to the file:

// RESET //
var codeRanOnce = false;
var tryTreeViewCloseInterval = null;
var tryTreeViewCloseIntervalCount = 0;


// EXECUTE CODE WHEN WORKSPACE IS OPENED //
atom.workspace.onDidOpen(function({item}){
	// make sure the code doesn't run twice
	if(codeRanOnce) return;
	
	// remember that the code ran once
	codeRanOnce = true;
	
	// schedule multiple tries to close the tree-view
	tryTreeViewClose();
	tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100);
});


// TRY TO CLOSE THE TREE-VIEW //
tryTreeViewClose = function(){
	// get tree-view element
	var treeView = atom.workspace.paneContainerForURI("atom://tree-view");
	
	// time out after too many tries
	tryTreeViewCloseIntervalCount++;
	if(tryTreeViewCloseIntervalCount >= 20){
		clearInterval(tryTreeViewCloseInterval);
		return;
	}
	
	// check if tree-view element exists
	if(!treeView) return;
	
	// check whether tree view contains projects
	var treeViewHasProjects = (treeView.element.querySelector("ol.tree-view-root") != null);
	
	// close the tree-view dock when the `Hidden On Startup` setting is activated or when it is empty
	let treeViewSettings = atom.packages.config.settings["tree-view"] ?? {};
	let hiddenOnStartup = treeViewSettings.hiddenOnStartup ?? false;
	if(hiddenOnStartup || !treeViewHasProjects){
		treeView.hide();
	}
	
	// stop trying
	clearInterval(tryTreeViewCloseInterval);
}

When the file is called init.coffee, add this snippet to the file:

## RESET ##
codeRanOnce = false
tryTreeViewCloseInterval = null
tryTreeViewCloseIntervalCount = 0


## EXECUTE CODE WHEN WORKSPACE IS OPENED ##
atom.workspace.onDidOpen ({item}) ->
	# make sure the code doesn't run twice
	if codeRanOnce then return
	
	# remember that the code ran once
	codeRanOnce = true
	
	# schedule multiple tries to close the tree-view
	tryTreeViewClose()
	tryTreeViewCloseInterval = setInterval(tryTreeViewClose, 100)


## TRY TO CLOSE THE TREE-VIEW ##
tryTreeViewClose = () ->
	# get tree-view element
	treeView = atom.workspace.paneContainerForURI("atom://tree-view")
	
	# time out after too many tries
	tryTreeViewCloseIntervalCount++
	if tryTreeViewCloseIntervalCount >= 20
		clearInterval(tryTreeViewCloseInterval)
		return;
	
	# check if tree-view element exists
	if !treeView then return;
	
	# check whether tree view contains projects
	treeViewHasProjects = (treeView.element.querySelector("ol.tree-view-root") != null)
	
	# close the tree-view dock when the `Hidden On Startup` setting is activated or when it is empty
	treeViewSettings = atom.packages.config.settings["tree-view"] ? {}
	hiddenOnStartup = treeViewSettings.hiddenOnStartup ? false
	if hiddenOnStartup || !treeViewHasProjects
		treeView.hide()
	
	# stop trying
	clearInterval(tryTreeViewCloseInterval)

Now you can configure whether you want the tree-view to be hidden on startup in the settings of the tree-view package:

Edit > Preferences > Packages > tree-view > Hidden On Startup

Hidden On Startup: checked: Always hide the tree-view on startup

Hidden On Startup: not checked: Only hide tree-view on startup when it does not contain open projects

Successfully tested using Pulsar v1.114.0