SideBySide2: Restore some old keybindings and fix help popup

Disable reverse search, restore "?" for help popup.
Map Ctrl+F to searching in CodeMirror, map Space to PageDown.
Take Ctrl+A back from Vim mode for selecting all text.
Disable Ctrl+O in Vim keymap since it's used by some browsers.
Add explanation of key commands to help popup.

'/' still starts a CodeMirror search instead of a Gerrit one.
Jumping within Gerrit using the 'g' prefix is still not supported.

Change-Id: Id77faa4b36add35c78edfd0d7d0611279cbe7120
This commit is contained in:
Michael Zhou
2013-11-07 05:50:19 -05:00
parent 3f6563d0a3
commit 6a45079cb6
8 changed files with 41 additions and 2 deletions

View File

@@ -24,6 +24,7 @@ public abstract class KeyCommand implements KeyPressHandler {
public static final int M_CTRL = 1 << 16; public static final int M_CTRL = 1 << 16;
public static final int M_ALT = 2 << 16; public static final int M_ALT = 2 << 16;
public static final int M_META = 4 << 16; public static final int M_META = 4 << 16;
public static final int M_SHIFT = 8 << 16;
public static boolean same(final KeyCommand a, final KeyCommand b) { public static boolean same(final KeyCommand a, final KeyCommand b) {
return a.getClass() == b.getClass() && a.helpText.equals(b.helpText); return a.getClass() == b.getClass() && a.helpText.equals(b.helpText);
@@ -58,6 +59,9 @@ public abstract class KeyCommand implements KeyPressHandler {
if ((keyMask & M_META) == M_META) { if ((keyMask & M_META) == M_META) {
modifier(b, KeyConstants.I.keyMeta()); modifier(b, KeyConstants.I.keyMeta());
} }
if ((keyMask & M_SHIFT) == M_SHIFT) {
modifier(b, KeyConstants.I.keyShift());
}
final char c = (char) (keyMask & 0xffff); final char c = (char) (keyMask & 0xffff);
switch (c) { switch (c) {

View File

@@ -32,6 +32,7 @@ public interface KeyConstants extends Constants {
String keyCtrl(); String keyCtrl();
String keyAlt(); String keyAlt();
String keyMeta(); String keyMeta();
String keyShift();
String keyEnter(); String keyEnter();
String keyEsc(); String keyEsc();
} }

View File

@@ -10,5 +10,6 @@ thenOtherKey = then
keyCtrl = Ctrl keyCtrl = Ctrl
keyAlt = Alt keyAlt = Alt
keyMeta = Meta keyMeta = Meta
keyShift = Shift
keyEnter = Enter keyEnter = Enter
keyEsc = Esc keyEsc = Esc

View File

@@ -316,12 +316,30 @@ public class SideBySide2 extends Screen {
(header.hasNext() ? header.next : header.up).go(); (header.hasNext() ? header.next : header.up).go();
} }
}) })
.on("Shift-Alt-/", new Runnable() { .on("Shift-/", new Runnable() {
@Override @Override
public void run() { public void run() {
new ShowHelpCommand().onKeyPress(null); new ShowHelpCommand().onKeyPress(null);
} }
}) })
.on("Ctrl-F", new Runnable() {
@Override
public void run() {
CodeMirror.handleVimKey(cm, "/");
}
})
.on("Space", new Runnable() {
@Override
public void run() {
CodeMirror.handleVimKey(cm, "<PageDown>");
}
})
.on("Ctrl-A", new Runnable() {
@Override
public void run() {
cm.execCommand("selectAll");
}
})
.on("N", maybeNextVimSearch(cm)) .on("N", maybeNextVimSearch(cm))
.on("P", diffChunkNav(cm, true)) .on("P", diffChunkNav(cm, true))
.on("Shift-O", openClosePublished(cm)) .on("Shift-O", openClosePublished(cm))
@@ -336,9 +354,13 @@ public class SideBySide2 extends Screen {
keysNavigation.add(new UpToChangeCommand2(revision, 0, 'u')); keysNavigation.add(new UpToChangeCommand2(revision, 0, 'u'));
keysNavigation.add(new NoOpKeyCommand(0, 'j', PatchUtil.C.lineNext())); keysNavigation.add(new NoOpKeyCommand(0, 'j', PatchUtil.C.lineNext()));
keysNavigation.add(new NoOpKeyCommand(0, 'k', PatchUtil.C.linePrev())); keysNavigation.add(new NoOpKeyCommand(0, 'k', PatchUtil.C.linePrev()));
keysNavigation.add(new NoOpKeyCommand(0, 'n', PatchUtil.C.chunkNext2()));
keysNavigation.add(new NoOpKeyCommand(0, 'p', PatchUtil.C.chunkPrev2()));
keysAction = new KeyCommandSet(Gerrit.C.sectionActions()); keysAction = new KeyCommandSet(Gerrit.C.sectionActions());
keysAction.add(new NoOpKeyCommand(0, 'o', PatchUtil.C.expandComment())); keysAction.add(new NoOpKeyCommand(0, 'o', PatchUtil.C.expandComment()));
keysAction.add(new NoOpKeyCommand(
KeyCommand.M_SHIFT, 'o', PatchUtil.C.expandAllCommentsOnCurrentLine()));
keysAction.add(new KeyCommand(0, 'r', PatchUtil.C.toggleReviewed()) { keysAction.add(new KeyCommand(0, 'r', PatchUtil.C.toggleReviewed()) {
@Override @Override
public void onKeyPress(KeyPressEvent event) { public void onKeyPress(KeyPressEvent event) {

View File

@@ -45,10 +45,13 @@ public interface PatchConstants extends Constants {
String lineNext(); String lineNext();
String chunkPrev(); String chunkPrev();
String chunkNext(); String chunkNext();
String chunkPrev2();
String chunkNext2();
String commentPrev(); String commentPrev();
String commentNext(); String commentNext();
String fileList(); String fileList();
String expandComment(); String expandComment();
String expandAllCommentsOnCurrentLine();
String toggleReviewed(); String toggleReviewed();
String markAsReviewedAndGoToNext(); String markAsReviewedAndGoToNext();

View File

@@ -27,10 +27,13 @@ linePrev = Previous line
lineNext = Next line lineNext = Next line
chunkPrev = Previous diff chunk or comment chunkPrev = Previous diff chunk or comment
chunkNext = Next diff chunk or comment chunkNext = Next diff chunk or comment
chunkPrev2 = Previous diff chunk
chunkNext2 = Next diff chunk or search result
commentPrev = Previous comment commentPrev = Previous comment
commentNext = Next comment commentNext = Next comment
fileList = Browse files in patch set fileList = Browse files in patch set
expandComment = Expand or collapse comment expandComment = Expand or collapse comment
expandAllCommentsOnCurrentLine = Expand or collapse all comments on current line
toggleReviewed = Toggle the reviewed flag toggleReviewed = Toggle the reviewed flag
markAsReviewedAndGoToNext = Mark patch as reviewed and go to next unreviewed patch markAsReviewedAndGoToNext = Mark patch as reviewed and go to next unreviewed patch

View File

@@ -291,6 +291,10 @@ public class CodeMirror extends JavaScriptObject {
return o; return o;
}-*/; }-*/;
public final native void execCommand(String cmd) /*-{
this.execCommand(cmd);
}-*/;
public static final native void addKeyMap(String name, KeyMap km) /*-{ public static final native void addKeyMap(String name, KeyMap km) /*-{
$wnd.CodeMirror.keyMap[name] = km; $wnd.CodeMirror.keyMap[name] = km;
}-*/; }-*/;

View File

@@ -90,7 +90,8 @@ class Loader {
private static void initVimKeys() { private static void initVimKeys() {
// TODO: Better custom keybindings, remove temporary navigation hacks. // TODO: Better custom keybindings, remove temporary navigation hacks.
KeyMap km = CodeMirror.cloneKeyMap("vim"); KeyMap km = CodeMirror.cloneKeyMap("vim");
for (String s : new String[] {"A", "C", "O", "R", "U", "Ctrl-C"}) { for (String s : new String[] {
"A", "C", "O", "R", "U", "Ctrl-C", "Ctrl-O"}) {
km.remove(s); km.remove(s);
} }
CodeMirror.addKeyMap("vim_ro", km); CodeMirror.addKeyMap("vim_ro", km);