Fix colors for insertion, deletion and and active lines

Previously, the colors for insertion and deletion were incorrect, and
the coloring of active lines was incomplete. Fixed by modifying the
CSS rules.

Change-Id: Ia4700481b3065fe45ae61953dd4c91fce03b1ed8
This commit is contained in:
Michael Zhou 2013-07-10 16:03:08 -07:00
parent 9d3820c9d1
commit 4e40cbd444
3 changed files with 29 additions and 23 deletions

View File

@ -266,8 +266,11 @@ public class CodeMirrorDemo extends Screen {
JsArrayString currentB = current.b() == null ? EMPTY : current.b();
int aLength = currentA.length();
int bLength = currentB.length();
colorLines(cmA, origLineA, aLength);
colorLines(cmB, origLineB, bLength);
String color = currentA == EMPTY || currentB == EMPTY
? diffTable.style.diff()
: diffTable.style.intralineBg();
colorLines(cmA, color, origLineA, aLength);
colorLines(cmB, color, origLineB, bLength);
mapper.appendCommon(Math.min(aLength, bLength));
if (aLength < bLength) { // Edit with insertion
int insertCnt = bLength - aLength;
@ -385,12 +388,12 @@ public class CodeMirrorDemo extends Screen {
return;
}
EditIterator iter = new EditIterator(lines, startLine);
Configuration intralineBgOpt = Configuration.create()
.set("className", diffTable.style.intralineBg())
.set("readOnly", true);
Configuration diffOpt = Configuration.create()
.set("className", diffTable.style.diff())
.set("readOnly", true);
Configuration editOpt = Configuration.create()
.set("className", diffTable.style.intraline())
.set("readOnly", true);
LineCharacter last = LineCharacter.create(0, 0);
for (int i = 0; i < edits.length(); i++) {
Span span = edits.get(i);
@ -398,22 +401,22 @@ public class CodeMirrorDemo extends Screen {
LineCharacter to = iter.advance(span.mark());
int fromLine = from.getLine();
if (last.getLine() == fromLine) {
cm.markText(last, from, diffOpt);
cm.markText(last, from, intralineBgOpt);
} else {
cm.markText(LineCharacter.create(fromLine, 0), from, diffOpt);
cm.markText(LineCharacter.create(fromLine, 0), from, intralineBgOpt);
}
cm.markText(from, to, editOpt);
cm.markText(from, to, diffOpt);
last = to;
for (int line = fromLine; line < to.getLine(); line++) {
cm.addLineClass(line, LineClassWhere.BACKGROUND,
diffTable.style.intraline());
diffTable.style.diff());
}
}
}
private void colorLines(CodeMirror cm, int line, int cnt) {
private void colorLines(CodeMirror cm, String color, int line, int cnt) {
for (int i = 0; i < cnt; i++) {
cm.addLineClass(line + i, LineClassWhere.WRAP, diffTable.style.diff());
cm.addLineClass(line + i, LineClassWhere.WRAP, color);
}
}

View File

@ -32,8 +32,8 @@ class DiffTable extends Composite {
private static Binder uiBinder = GWT.create(Binder.class);
interface LineStyle extends CssResource {
String intralineBg();
String diff();
String intraline();
String padding();
String activeLine();
String activeLineBg();

View File

@ -31,21 +31,23 @@ limitations under the License.
.a, .b {
width: 50%;
}
.a .intralineBg,
.a .intralineBg .CodeMirror-linenumber {
background-color: #fee;
}
.b .intralineBg,
.b .intralineBg .CodeMirror-linenumber {
background-color: #dfd;
}
.a .diff,
.a .diff .CodeMirror-linenumber {
background-color: #fee;
background-color: #faa;
}
.b .diff,
.b .diff .CodeMirror-linenumber {
background-color: #dfd;
}
.a .intraline {
background-color: #faa;
}
.b .intraline {
background-color: #9f9;
}
.CodeMirror-selectedtext.diff, .CodeMirror-selectedtext.intraline {
.CodeMirror-selectedtext.diff, .CodeMirror-selectedtext.intralineBg {
background-color: inherit;
}
.padding {
@ -57,11 +59,12 @@ limitations under the License.
.a .CodeMirror-vscrollbar {
display: none !important;
}
.activeLine .CodeMirror-linenumber {
background-color: #D8EDF9;
.activeLine .CodeMirror-linenumber,
.activeLine .diff, .activeLine .intralineBg {
background-color: #D8EDF9 !important;
}
.activeLineBg {
background-color: #D8EDF9;
background-color: #D8EDF9 !important;
}
</ui:style>
<g:HTMLPanel styleName='{style.difftable}'>