Created
March 9, 2016 23:32
-
-
Save notacouch/e148c2b6aa50289c3b09 to your computer and use it in GitHub Desktop.
Atom Tab Bar should scroll tab into view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
` | |
var next_active_file_timer = 0; | |
atom.commands.onDidDispatch(function(event){ | |
//console.log('event type: ', event.type); | |
clearTimeout(next_active_file_timer); | |
if (event.type === 'tree-view:reveal-active-file') { | |
next_active_file_timer = setTimeout(function(){ | |
var $ = atom.document.querySelector; | |
var $pane = $.call(atom.document, '.panes'); | |
var $bar = $.call(atom.document, '.panes .tab-bar'); | |
var $active = $.call(atom.document, '.panes .tab.active'); | |
var w = $pane.offsetWidth; | |
var mid = w/2; | |
var bar_x = $bar.scrollLeft; | |
var active_x = $active.offsetLeft; | |
//console.log('vars: ', mid, w, bar_x, bar_x + w, active_x, event); | |
if (active_x > (bar_x + w)) { | |
$bar.scrollLeft = active_x - mid; | |
} else if (active_x < bar_x) { | |
if (active_x > w) { | |
$bar.scrollLeft = active_x - mid; | |
} else { | |
$bar.scrollLeft = 0; | |
} | |
} | |
}, 100); | |
} | |
return event; | |
}); | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment