Take "n" back from vim if no search result is being highlighted

Alt- doesn't work well as a modifier. Vim mode clears search
highlights if the user presses Esc on the query box, Take "n"
back in this case.

Note that vim mode behaves slightly different from the actual
vim, in which pressing Esc (twice) still keeps the results
highlighted.

Change-Id: I600b0625ecded6b1678231d4054952f532889bc5
This commit is contained in:
Michael Zhou
2013-08-20 17:19:30 -07:00
parent b7bf30b0c2
commit 79f7e480c2
2 changed files with 24 additions and 2 deletions

View File

@@ -330,8 +330,8 @@ public class SideBySide2 extends Screen {
new ShowHelpCommand().onKeyPress(null);
}
})
.on("Alt-N", diffChunkNav(cm, false))
.on("Alt-P", diffChunkNav(cm, true))
.on("N", maybeNextVimSearch(cm))
.on("P", diffChunkNav(cm, true))
.on("Shift-O", openClosePublished(cm))
.on("Shift-Left", flipCursorSide(cm, true))
.on("Shift-Right", flipCursorSide(cm, false)));
@@ -1150,6 +1150,19 @@ public class SideBySide2 extends Screen {
};
}
private Runnable maybeNextVimSearch(final CodeMirror cm) {
return new Runnable() {
@Override
public void run() {
if (cm.hasVimSearchHighlight()) {
CodeMirror.handleVimKey(cm, "n");
} else {
diffChunkNav(cm, false).run();
}
}
};
}
private Runnable diffChunkNav(final CodeMirror cm, final boolean prev) {
return new Runnable() {
@Override

View File

@@ -307,6 +307,15 @@ public class CodeMirror extends JavaScriptObject {
$wnd.CodeMirror.keyMap[name] = km;
}-*/;
public static final native void handleVimKey(CodeMirror cm, String key) /*-{
$wnd.CodeMirror.Vim.handleKey(cm, key);
}-*/;
public final native boolean hasVimSearchHighlight() /*-{
return this.state.vim && this.state.vim.searchState_ &&
!!this.state.vim.searchState_.getOverlay();
}-*/;
protected CodeMirror() {
}