EditScreen: Support ":w" in CodeMirror's Vim keymap
The Vim keymap can make use of a custom save command defined in the CodeMirror.commands object. Adding this custom command allows EditScreen to perform the actual save action instead of showing an obscure TypeError. Change-Id: I5bf01d520ed9a299685736368f43847f9bd33b63
This commit is contained in:
@@ -71,6 +71,7 @@ import com.google.gwtexpui.safehtml.client.SafeHtml;
|
|||||||
|
|
||||||
import net.codemirror.lib.CodeMirror;
|
import net.codemirror.lib.CodeMirror;
|
||||||
import net.codemirror.lib.CodeMirror.ChangesHandler;
|
import net.codemirror.lib.CodeMirror.ChangesHandler;
|
||||||
|
import net.codemirror.lib.CodeMirror.CommandRunner;
|
||||||
import net.codemirror.lib.Configuration;
|
import net.codemirror.lib.Configuration;
|
||||||
import net.codemirror.lib.KeyMap;
|
import net.codemirror.lib.KeyMap;
|
||||||
import net.codemirror.lib.Pos;
|
import net.codemirror.lib.Pos;
|
||||||
@@ -435,6 +436,13 @@ public class EditScreen extends Screen {
|
|||||||
.set("keyMap", prefs.keyMapType().name().toLowerCase())
|
.set("keyMap", prefs.keyMapType().name().toLowerCase())
|
||||||
.set("theme", prefs.theme().name().toLowerCase())
|
.set("theme", prefs.theme().name().toLowerCase())
|
||||||
.set("mode", mode != null ? mode.mode() : null));
|
.set("mode", mode != null ? mode.mode() : null));
|
||||||
|
|
||||||
|
CodeMirror.addCommand("save", new CommandRunner() {
|
||||||
|
@Override
|
||||||
|
public void run(CodeMirror instance) {
|
||||||
|
save().run();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderLinks(EditFileInfo editInfo,
|
private void renderLinks(EditFileInfo editInfo,
|
||||||
|
|||||||
@@ -364,6 +364,13 @@ public class CodeMirror extends JavaScriptObject {
|
|||||||
$wnd.CodeMirror.keyMap[name] = km
|
$wnd.CodeMirror.keyMap[name] = km
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
|
public static final native void addCommand(String name, CommandRunner runner) /*-{
|
||||||
|
$wnd.CodeMirror.commands[name] = function(cm) {
|
||||||
|
runner.@net.codemirror.lib.CodeMirror.CommandRunner::run(
|
||||||
|
Lnet/codemirror/lib/CodeMirror;)(cm);
|
||||||
|
};
|
||||||
|
}-*/;
|
||||||
|
|
||||||
public final native Vim vim() /*-{
|
public final native Vim vim() /*-{
|
||||||
return this;
|
return this;
|
||||||
}-*/;
|
}-*/;
|
||||||
@@ -428,4 +435,8 @@ public class CodeMirror extends JavaScriptObject {
|
|||||||
public interface ChangesHandler {
|
public interface ChangesHandler {
|
||||||
void handle(CodeMirror instance);
|
void handle(CodeMirror instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface CommandRunner {
|
||||||
|
void run(CodeMirror instance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user