Add addon to highlight trailing whitespace

Added edit/trailingspace.js to highlight trailing whitespace
in red.

Fixed to not highlight active line when something is selected.

Change-Id: Ife3e0939f6fed0bf8e3a07a80337750880731f54
This commit is contained in:
Michael Zhou 2013-07-10 17:41:31 -07:00
parent 595d6f65f5
commit fe4e246aa8
5 changed files with 22 additions and 4 deletions

View File

@ -255,6 +255,7 @@ public class CodeMirrorDemo extends Screen {
.set("tabSize", 2)
.set("mode", getContentType(meta))
.set("styleSelectedText", true)
.set("showTrailingSpace", true)
.set("value", contents);
final CodeMirror cm = CodeMirror.create(ele, cfg);
cm.setHeight(Window.getClientHeight() - HEADER_FOOTER);
@ -606,12 +607,15 @@ public class CodeMirrorDemo extends Screen {
line -= hiddenSkipMap.get(handle);
handle = cm.getLineHandle(line);
}
cm.setActiveLine(handle);
if (cm.somethingSelected()) {
return;
}
cm.addLineClass(line, LineClassWhere.WRAP, diffTable.style.activeLine());
cm.addLineClass(line, LineClassWhere.BACKGROUND, diffTable.style.activeLineBg());
LineOnOtherInfo info =
mapper.lineOnOther(cm == cmA ? Side.PARENT : Side.REVISION, line);
int oLine = info.getLine();
cm.setActiveLine(handle);
cm.addLineClass(line, LineClassWhere.WRAP, diffTable.style.activeLine());
cm.addLineClass(line, LineClassWhere.BACKGROUND, diffTable.style.activeLineBg());
if (info.isAligned()) {
other.setActiveLine(other.getLineHandle(oLine));
other.addLineClass(oLine, LineClassWhere.WRAP,

View File

@ -20,6 +20,7 @@ limitations under the License.
@external .CodeMirror, .CodeMirror-selectedtext;
@external .CodeMirror-linenumber, .CodeMirror-vscrollbar;
@external .CodeMirror-hscrollbar;
@external .cm-trailingspace;
.difftable .CodeMirror pre {
padding: 0;
overflow: hidden;
@ -48,7 +49,7 @@ limitations under the License.
background-color: #9f9;
}
.CodeMirror-selectedtext.diff, .CodeMirror-selectedtext.intralineBg {
background-color: inherit;
background-color: inherit !important;
}
.padding {
background-color: #eee;
@ -66,6 +67,9 @@ limitations under the License.
.activeLineBg {
background-color: #D8EDF9 !important;
}
.cm-trailingspace {
background-color: red !important;
}
</ui:style>
<g:HTMLPanel styleName='{style.difftable}'>
<table class='{style.table}'>

View File

@ -25,4 +25,8 @@ public interface Addons extends ClientBundle {
@Source("selection/mark-selection.js")
@DoNotEmbed
DataResource mark_selection();
@Source("edit/trailingspace.js")
@DoNotEmbed
DataResource trailingspace();
}

View File

@ -137,6 +137,10 @@ public class CodeMirror extends JavaScriptObject {
return this.getCursor(start);
}-*/;
public final native boolean somethingSelected() /*-{
return this.somethingSelected();
}-*/;
public final native boolean hasActiveLine() /*-{
return this.state.hasOwnProperty('activeLine');
}-*/;

View File

@ -44,6 +44,8 @@ class Loader {
injectScript(Lib.I.js().getSafeUri(),
group.add(CallbackGroup.<Void>emptyCallback()));
injectScript(Addons.I.mark_selection().getSafeUri(),
group.add(CallbackGroup.<Void>emptyCallback()));
injectScript(Addons.I.trailingspace().getSafeUri(),
group.addFinal(cb));
}
}