mbg notes

Massive Brain Games developers notes

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.

Hierarchy: previous

Comments

There are 0 comments on this post. Post yours →

Post a comment

Required fields in bold.