Jumping between diffs (addon merge)

Using the addon merge I tried to make it possible for the user to jump to the previous or next diff by clicking on a button. The problem I faced was that after clicking the button the focus was not (permanently) set, so another click would do nothing (only after manually setting the focus with a mouseclick inside one of the editors another click on the button would again do the jump).

To solve this I added one line to the function goNearbyDiff in merge.js (the line after the variable initialization line).

function goNearbyDiff(cm, dir) {
var found = null, views = cm.state.diffViews, line = cm.getCursor().line;
if (line <= 0) line = (dir < 0 ? 1 + cm.lineAtHeight(0) : 1 + cm.lineAtHeight(cm.display.wrapper.clientHeight));

Thus if no cursor position is present the variable line is set to the (more or less) top visible line to find the previous diff, to the (more or less) bottom visible line to find the next diff.

Wouldn’t calling preventDefault on the click handled by the button, and thus preventing focus from being lost, be a cleaner solution?

I wasn’t aware of this function, thank you! I’ve checked it, and you are right, it more or less would also solve the problem.

I’ve just noticed one little thing that doesn’t seem to work as desired: when after jumping the user scrolls somewhere (without touching the content) and then again clicks on a jump button it doesn’t always do the right jump (in some cases doesn’t do anything).