Merge "DiffScreen: Improve search experience with Ctrl-F, Ctrl-G, etc."
This commit is contained in:
@@ -80,7 +80,7 @@ import java.util.List;
|
|||||||
/** Base class for SideBySide and Unified */
|
/** Base class for SideBySide and Unified */
|
||||||
abstract class DiffScreen extends Screen {
|
abstract class DiffScreen extends Screen {
|
||||||
static final KeyMap RENDER_ENTIRE_FILE_KEYMAP = KeyMap.create()
|
static final KeyMap RENDER_ENTIRE_FILE_KEYMAP = KeyMap.create()
|
||||||
.propagate("Ctrl-F");
|
.propagate("Ctrl-F").propagate("Ctrl-G").propagate("Shift-Ctrl-G");
|
||||||
|
|
||||||
enum FileSize {
|
enum FileSize {
|
||||||
SMALL(0),
|
SMALL(0),
|
||||||
@@ -317,7 +317,6 @@ abstract class DiffScreen extends Screen {
|
|||||||
.on("']'", header.navigate(Direction.NEXT))
|
.on("']'", header.navigate(Direction.NEXT))
|
||||||
.on("R", header.toggleReviewed())
|
.on("R", header.toggleReviewed())
|
||||||
.on("O", getCommentManager().toggleOpenBox(cm))
|
.on("O", getCommentManager().toggleOpenBox(cm))
|
||||||
.on("Enter", getCommentManager().toggleOpenBox(cm))
|
|
||||||
.on("N", maybeNextVimSearch(cm))
|
.on("N", maybeNextVimSearch(cm))
|
||||||
.on("Ctrl-Alt-E", openEditScreen(cm))
|
.on("Ctrl-Alt-E", openEditScreen(cm))
|
||||||
.on("P", getChunkManager().diffChunkNav(cm, Direction.PREV))
|
.on("P", getChunkManager().diffChunkNav(cm, Direction.PREV))
|
||||||
@@ -367,7 +366,34 @@ abstract class DiffScreen extends Screen {
|
|||||||
.on("Ctrl-F", new Runnable() {
|
.on("Ctrl-F", new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
cm.vim().handleKey("/");
|
cm.execCommand("find");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("Ctrl-G", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
cm.execCommand("findNext");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("Enter", maybeNextCmSearch(cm))
|
||||||
|
.on("Shift-Ctrl-G", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
cm.execCommand("findPrev");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("Shift-Enter", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
cm.execCommand("findPrev");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.on("Esc", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
cm.setCursor(cm.getCursor());
|
||||||
|
cm.execCommand("clearSearch");
|
||||||
|
cm.vim().handleEx("nohlsearch");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on("Ctrl-A", new Runnable() {
|
.on("Ctrl-A", new Runnable() {
|
||||||
@@ -786,6 +812,20 @@ abstract class DiffScreen extends Screen {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Runnable maybeNextCmSearch(final CodeMirror cm) {
|
||||||
|
return new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (cm.hasSearchHighlight()) {
|
||||||
|
cm.execCommand("findNext");
|
||||||
|
} else {
|
||||||
|
cm.execCommand("clearSearch");
|
||||||
|
getCommentManager().toggleOpenBox(cm).run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
boolean renderEntireFile() {
|
boolean renderEntireFile() {
|
||||||
return prefs.renderEntireFile() && canRenderEntireFile(prefs);
|
return prefs.renderEntireFile() && canRenderEntireFile(prefs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -395,6 +395,10 @@ public class CodeMirror extends JavaScriptObject {
|
|||||||
return this.setGutterMarker(line, gutterId, value);
|
return this.setGutterMarker(line, gutterId, value);
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
|
public final native boolean hasSearchHighlight() /*-{
|
||||||
|
return this.state.search && !!this.state.search.query;
|
||||||
|
}-*/;
|
||||||
|
|
||||||
protected CodeMirror() {
|
protected CodeMirror() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ public class Vim extends JavaScriptObject {
|
|||||||
$wnd.CodeMirror.Vim.handleKey(this, key)
|
$wnd.CodeMirror.Vim.handleKey(this, key)
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
|
public final native void handleEx(String exCommand) /*-{
|
||||||
|
$wnd.CodeMirror.Vim.handleEx(this, exCommand);
|
||||||
|
}-*/;
|
||||||
|
|
||||||
public final native boolean hasSearchHighlight() /*-{
|
public final native boolean hasSearchHighlight() /*-{
|
||||||
var v = this.state.vim;
|
var v = this.state.vim;
|
||||||
return v && v.searchState_ && !!v.searchState_.getOverlay();
|
return v && v.searchState_ && !!v.searchState_.getOverlay();
|
||||||
|
|||||||
Reference in New Issue
Block a user