Keyboard navigation for TextMate stacktraces
Posted by Ivan Schneider on June 29, 2008 at 11:49 PM
I love the fact that in TextMate almost anything has a keyboard shortcut or can be assigned one. However there is still one action that requires me to resort to the mouse; clicking the links in a stacktrace to get to the incriminating file. This led me to write this JavaScript snippet:
document.addEventListener('keypress', function(e){
var key = e.keyCode
if (key != 63233 && key != 63232) return
links = document.getElementsByTagName('a')
for (var i = 1; i < links.length; i++)
if (links[i].title == 'focused') break
if (i == links.length) i = 0
links[i].title = null
if (key == 63233){
if (i == (links.length - 1)) i = 1
else i += 1
}
if (key == 63232){
if (i <= 1) i = links.length - 1
else i -= 1
}
links[i].title = 'focused'
links[i].focus()
})
It allows to navigate through the links of the html output with the up and down arrows and then pressing enter opens the file. I don't need the mouse for that anymore, mission accomplished.
I put this script at the end of /Applications/TextMate.app/Contents/SharedSupport/Support/script/webpreview.js. There might be a cleaner place to put this, but I didn't find it right away so I settled for this though I might have to re-paste it at the next TextMate update.
Comments
There are 3 comments on this post. Post yours →
I think if you put it there it will get overridden on the next TextMate update.
You have a personal "Support" folder at:
~/Library/Application\ Support/TextMate/Support
I have a 'svn co' of the Support folder here and do 'svn up' every now and then to get the latest.
Also, I think you could jump on ##textmate and offer the patch to Allan or Michael Sheets.
This is great! Hope Allan will like this too, so we don't need to paste it again after upgrade to TextMate next version(2.0?).
Thanks Ivan!
Will it be working If I have document in frame?
Post a comment
Required fields in bold.