EditScreen: Pass MIME type instead of mode name to CodeMirror

Currently, modes are specified with mode names such as "clike". The
result of the syntax highlighting is not great if the source is a Java
file, because the clike mode doesn't know which language to specialize.

This change passes the MIME type such as "text/x-java" to CodeMirror,
which will then use its mode/meta.js to pass this piece of additional
information to the modes. DiffScreen already does that, and the syntax
highlighting is much better for Java files.

Change-Id: I7e3a31235eb92ea6a44bb1cf65aa761c252176fb
This commit is contained in:
Michael Zhou
2016-04-26 00:30:33 -04:00
parent d03fe284e7
commit 0584ef737b

View File

@@ -381,7 +381,7 @@ public class EditScreen extends Screen {
void setSyntaxHighlighting(boolean b) {
ModeInfo modeInfo = ModeInfo.findMode(content.getContentType(), path);
final String mode = modeInfo != null ? modeInfo.mode() : null;
final String mode = modeInfo != null ? modeInfo.mime() : null;
if (b && mode != null && !mode.isEmpty()) {
injectMode(mode, new AsyncCallback<Void>() {
@Override
@@ -421,7 +421,7 @@ public class EditScreen extends Screen {
.set("lineNumbers", prefs.hideLineNumbers())
.set("lineWrapping", false)
.set("matchBrackets", prefs.matchBrackets())
.set("mode", mode != null ? mode.mode() : null)
.set("mode", mode != null ? mode.mime() : null)
.set("readOnly", false)
.set("scrollbarStyle", "overlay")
.set("showTrailingSpace", prefs.showWhitespaceErrors())