Add keyboard shortcuts and VIM bindings

Added global keyboard shortcuts.

Added shortcuts for:
- Opening / closing comment boxes.
- Saving drafts.
- Going up to change.

Included CodeMirror's VIM bindings for navigation. Removed the ones
that trigger insert mode. We probably need a way to include only a
subset of VIM bindings.

Fixed CodeMirror.on(). Added EventHandler for handling more types of
events.

Removed hiddenSkipMap hack and imported CodeMirror's official fix.

Change-Id: I75923e20e27434ca95882e2d70d10346bdf2323c
This commit is contained in:
Michael Zhou
2013-07-11 15:43:56 -07:00
parent 1ee35db3d6
commit 8add596333
12 changed files with 294 additions and 69 deletions

View File

@@ -27,14 +27,11 @@ import com.google.gwt.user.client.ui.HTMLPanel;
import net.codemirror.lib.CodeMirror;
import net.codemirror.lib.CodeMirror.LineClassWhere;
import net.codemirror.lib.CodeMirror.LineHandle;
import net.codemirror.lib.Configuration;
import net.codemirror.lib.LineWidget;
import net.codemirror.lib.TextMarker;
import net.codemirror.lib.TextMarker.FromTo;
import java.util.Map;
/** The Widget that handles expanding of skipped lines */
class SkipBar extends Composite {
interface Binder extends UiBinder<HTMLPanel, SkipBar> {}
@@ -67,11 +64,9 @@ class SkipBar extends Composite {
private SkipBar otherBar;
private CodeMirror cm;
private int numSkipLines;
private Map<LineHandle, Integer> hiddenSkipMap;
SkipBar(CodeMirror cm, Map<LineHandle, Integer> hiddenSkipMap) {
SkipBar(CodeMirror cm) {
this.cm = cm;
this.hiddenSkipMap = hiddenSkipMap;
skipNum = new Anchor(true);
upArrow = new Anchor(true);
downArrow = new Anchor(true);
@@ -123,10 +118,9 @@ class SkipBar extends Composite {
}
private void expandAll() {
hiddenSkipMap.remove(
cm.getLineHandle(marker.find().getTo().getLine()));
clearMarkerAndWidget();
removeFromParent();
cm.focus();
}
private void expandBefore() {
@@ -140,7 +134,7 @@ class SkipBar extends Composite {
LineWidget newWidget = cm.addLineWidget(newStart, getElement(), config);
setWidget(newWidget);
updateSkipNum();
hiddenSkipMap.put(cm.getLineHandle(end), numSkipLines);
cm.focus();
}
private void expandAfter() {
@@ -152,8 +146,7 @@ class SkipBar extends Composite {
CodeMirror.pos(newEnd),
COLLAPSED);
updateSkipNum();
hiddenSkipMap.remove(cm.getLineHandle(oldEnd));
hiddenSkipMap.put(cm.getLineHandle(newEnd), numSkipLines);
cm.focus();
}
@UiHandler("skipNum")