Simplify CodeMirror wrapper JSNI

LineCharacter (aka {from, to} objects) is the same as Pos in
CodeMirror.  The CodeMirror documentation suggests using a Pos
object in a number of function calls, but it can be unclear this
is the LineCharacter wrapper in Gerrit

Rename LineCharacter to Pos, and change its factory methods to
construct using CodeMirror.Pos(line, ch) so instances are of the
type CodeMirror expects internally.

Simplify accessor methods by dropping the get/set Java idiom and
use the field name as the method name. Argument overloading makes
it possible to identify between a get and a set variant. This makes
these lightweight JSNI wrappers feel more like an @AutoValue object
or raw JavaScript code that they are interacting with.

Change-Id: If73536652cc5559fcef5b2519cb686460a126ff5
This commit is contained in:
Shawn Pearce
2014-12-29 15:10:28 -05:00
parent 3c9816c3cc
commit 6cadc12269
22 changed files with 337 additions and 337 deletions

View File

@@ -32,7 +32,7 @@ import com.google.gwt.user.client.EventListener;
import net.codemirror.lib.CodeMirror;
import net.codemirror.lib.CodeMirror.LineClassWhere;
import net.codemirror.lib.Configuration;
import net.codemirror.lib.LineCharacter;
import net.codemirror.lib.Pos;
import net.codemirror.lib.LineWidget;
import net.codemirror.lib.TextMarker;
@@ -217,20 +217,20 @@ class ChunkManager {
.set("className", DiffTable.style.diff())
.set("readOnly", true);
LineCharacter last = CodeMirror.pos(0, 0);
Pos last = Pos.create(0, 0);
for (Span span : Natives.asList(edits)) {
LineCharacter from = iter.advance(span.skip());
LineCharacter to = iter.advance(span.mark());
if (from.getLine() == last.getLine()) {
Pos from = iter.advance(span.skip());
Pos to = iter.advance(span.mark());
if (from.line() == last.line()) {
markers.add(cm.markText(last, from, bg));
} else {
markers.add(cm.markText(CodeMirror.pos(from.getLine(), 0), from, bg));
markers.add(cm.markText(Pos.create(from.line(), 0), from, bg));
}
markers.add(cm.markText(from, to, diff));
last = to;
colorLines(cm, LineClassWhere.BACKGROUND,
DiffTable.style.diff(),
from.getLine(), to.getLine());
from.line(), to.line());
}
}
@@ -291,7 +291,7 @@ class ChunkManager {
return new Runnable() {
@Override
public void run() {
int line = cm.hasActiveLine() ? cm.getLineNumber(cm.getActiveLine()) : 0;
int line = cm.hasActiveLine() ? cm.getLineNumber(cm.activeLine()) : 0;
int res = Collections.binarySearch(
chunks,
new DiffChunkInfo(cm.side(), line, 0, false),
@@ -315,11 +315,11 @@ class ChunkManager {
DiffChunkInfo target = chunks.get(res);
CodeMirror targetCm = host.getCmFromSide(target.getSide());
targetCm.setCursor(LineCharacter.create(target.getStart()));
targetCm.setCursor(Pos.create(target.getStart()));
targetCm.focus();
targetCm.scrollToY(
targetCm.heightAtLine(target.getStart(), "local") -
0.5 * cmB.getScrollbarV().getClientHeight());
0.5 * cmB.scrollbarV().getClientHeight());
}
};
}

View File

@@ -58,8 +58,8 @@ abstract class CommentBox extends Composite {
if (range != null) {
fromTo = FromTo.create(range);
rangeMarker = group.getCm().markText(
fromTo.getFrom(),
fromTo.getTo(),
fromTo.from(),
fromTo.to(),
Configuration.create()
.set("className", DiffTable.style.range()));
}
@@ -106,8 +106,8 @@ abstract class CommentBox extends Composite {
if (fromTo != null) {
if (highlight && rangeHighlightMarker == null) {
rangeHighlightMarker = group.getCm().markText(
fromTo.getFrom(),
fromTo.getTo(),
fromTo.from(),
fromTo.to(),
Configuration.create()
.set("className", DiffTable.style.rangeHighlight()));
} else if (!highlight && rangeHighlightMarker != null) {

View File

@@ -218,8 +218,8 @@ class CommentGroup extends Composite {
private void updateSelection() {
if (cm.somethingSelected()) {
FromTo r = cm.getSelectedRange();
if (r.getTo().getLine() >= line) {
cm.setSelection(r.getFrom(), r.getTo());
if (r.to().line() >= line) {
cm.setSelection(r.from(), r.to());
}
}
}

View File

@@ -26,7 +26,7 @@ import com.google.gwt.core.client.JsArray;
import net.codemirror.lib.CodeMirror;
import net.codemirror.lib.CodeMirror.LineHandle;
import net.codemirror.lib.LineCharacter;
import net.codemirror.lib.Pos;
import net.codemirror.lib.TextMarker.FromTo;
import java.util.ArrayList;
@@ -92,7 +92,7 @@ class CommentManager {
// on either side of the editor pair.
SortedMap<Integer, CommentGroup> map = map(src.side());
int line = src.hasActiveLine()
? src.getLineNumber(src.getActiveLine()) + 1
? src.getLineNumber(src.activeLine()) + 1
: 0;
if (dir == Direction.NEXT) {
map = map.tailMap(line + 1);
@@ -115,8 +115,8 @@ class CommentManager {
CodeMirror cm = g.getCm();
double y = cm.heightAtLine(g.getLine() - 1, "local");
cm.setCursor(LineCharacter.create(g.getLine() - 1));
cm.scrollToY(y - 0.5 * cm.getScrollbarV().getClientHeight());
cm.setCursor(Pos.create(g.getLine() - 1));
cm.scrollToY(y - 0.5 * cm.scrollbarV().getClientHeight());
cm.focus();
}
};
@@ -297,7 +297,7 @@ class CommentManager {
public void run() {
if (cm.hasActiveLine()) {
CommentGroup w = map(cm.side()).get(
cm.getLineNumber(cm.getActiveLine()) + 1);
cm.getLineNumber(cm.activeLine()) + 1);
if (w != null) {
w.openCloseLast();
}
@@ -312,7 +312,7 @@ class CommentManager {
public void run() {
if (cm.hasActiveLine()) {
CommentGroup w = map(cm.side()).get(
cm.getLineNumber(cm.getActiveLine()) + 1);
cm.getLineNumber(cm.activeLine()) + 1);
if (w != null) {
w.openCloseAll();
}
@@ -328,7 +328,7 @@ class CommentManager {
public void run() {
String token = host.getToken();
if (cm.hasActiveLine()) {
LineHandle handle = cm.getActiveLine();
LineHandle handle = cm.activeLine();
int line = cm.getLineNumber(handle) + 1;
token += "@" + (cm.side() == DisplaySide.A ? "a" : "") + line;
}
@@ -348,13 +348,13 @@ class CommentManager {
}
private void newDraft(CodeMirror cm) {
int line = cm.getLineNumber(cm.getActiveLine()) + 1;
int line = cm.getLineNumber(cm.activeLine()) + 1;
if (cm.somethingSelected()) {
FromTo fromTo = cm.getSelectedRange();
LineCharacter end = fromTo.getTo();
if (end.getCh() == 0) {
end.setLine(end.getLine() - 1);
end.setCh(cm.getLine(end.getLine()).length());
Pos end = fromTo.to();
if (end.ch() == 0) {
end.line(end.line() - 1);
end.ch(cm.getLine(end.line()).length());
}
addDraftBox(cm.side(), CommentInfo.create(

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.client.diff;
import com.google.gwt.core.client.JavaScriptObject;
import net.codemirror.lib.LineCharacter;
import net.codemirror.lib.Pos;
import net.codemirror.lib.TextMarker.FromTo;
public class CommentRange extends JavaScriptObject {
@@ -31,11 +31,11 @@ public class CommentRange extends JavaScriptObject {
return null;
}
LineCharacter from = fromTo.getFrom();
LineCharacter to = fromTo.getTo();
Pos from = fromTo.from();
Pos to = fromTo.to();
return create(
from.getLine() + 1, from.getCh(),
to.getLine() + 1, to.getCh());
from.line() + 1, from.ch(),
to.line() + 1, to.ch());
}
public final native int start_line() /*-{ return this.start_line; }-*/;

View File

@@ -243,7 +243,7 @@ class DraftBox extends CommentBox {
private void restoreSelection() {
if (getFromTo() != null && comment.in_reply_to() == null) {
getCm().setSelection(getFromTo().getFrom(), getFromTo().getTo());
getCm().setSelection(getFromTo().from(), getFromTo().to());
}
}

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.client.diff;
import com.google.gwt.core.client.JsArrayString;
import net.codemirror.lib.LineCharacter;
import net.codemirror.lib.Pos;
/** An iterator for intraline edits */
class EditIterator {
@@ -30,13 +30,13 @@ class EditIterator {
startLine = start;
}
LineCharacter advance(int numOfChar) {
Pos advance(int numOfChar) {
numOfChar = adjustForNegativeDelta(numOfChar);
while (line < lines.length()) {
int len = lines.get(line).length() - pos + 1; // + 1 for LF
if (numOfChar < len) {
LineCharacter at = LineCharacter.create(
Pos at = Pos.create(
startLine + line,
numOfChar + pos);
pos += numOfChar;
@@ -48,7 +48,7 @@ class EditIterator {
pos = 0;
if (numOfChar == 0) {
return LineCharacter.create(startLine + line, 0);
return Pos.create(startLine + line, 0);
}
}

View File

@@ -43,9 +43,9 @@ class ScrollSynchronizer {
}
private void updateScreenHeader(ScrollInfo si) {
if (si.getTop() == 0 && !diffTable.isHeaderVisible()) {
if (si.top() == 0 && !diffTable.isHeaderVisible()) {
diffTable.setHeaderVisible(true);
} else if (si.getTop() > 0.5 * si.getClientHeight()
} else if (si.top() > 0.5 * si.clientHeight()
&& diffTable.isHeaderVisible()) {
diffTable.setHeaderVisible(false);
}
@@ -73,7 +73,7 @@ class ScrollSynchronizer {
}
void sync() {
dst.scrollToY(align(src.getScrollInfo().getTop()));
dst.scrollToY(align(src.getScrollInfo().top()));
}
@Override
@@ -85,7 +85,7 @@ class ScrollSynchronizer {
if (active == this) {
ScrollInfo si = src.getScrollInfo();
updateScreenHeader(si);
dst.scrollTo(si.getLeft(), align(si.getTop()));
dst.scrollTo(si.left(), align(si.top()));
state = 0;
}
}
@@ -94,7 +94,7 @@ class ScrollSynchronizer {
switch (state) {
case 0:
state = 1;
dst.scrollToY(align(src.getScrollInfo().getTop()));
dst.scrollToY(align(src.getScrollInfo().top()));
break;
case 1:
state = 2;

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.client.diff;
import com.google.gwt.resources.client.CssResource;
import net.codemirror.lib.CodeMirror;
import net.codemirror.lib.Pos;
import java.util.ArrayList;
import java.util.List;
@@ -84,7 +85,7 @@ class Scrollbar {
private ScrollbarAnnotation diff(CodeMirror cm, int s, int n) {
ScrollbarAnnotation a = new ScrollbarAnnotation(cm);
a.at(CodeMirror.pos(s), CodeMirror.pos(s + n));
a.at(Pos.create(s), Pos.create(s + n));
diff.add(a);
return a;
}

View File

@@ -23,15 +23,15 @@ import com.google.gwt.user.client.ui.Widget;
import net.codemirror.lib.CodeMirror;
import net.codemirror.lib.CodeMirror.RegisteredHandler;
import net.codemirror.lib.LineCharacter;
import net.codemirror.lib.Pos;
/** Displayed on the vertical scrollbar to place a chunk or comment. */
class ScrollbarAnnotation extends Widget implements ClickHandler {
private final CodeMirror cm;
private CodeMirror cmB;
private RegisteredHandler refresh;
private LineCharacter from;
private LineCharacter to;
private Pos from;
private Pos to;
private double scale;
ScrollbarAnnotation(CodeMirror cm) {
@@ -47,10 +47,10 @@ class ScrollbarAnnotation extends Widget implements ClickHandler {
}
void at(int line) {
at(CodeMirror.pos(line), CodeMirror.pos(line + 1));
at(Pos.create(line), Pos.create(line + 1));
}
void at(LineCharacter from, LineCharacter to) {
void at(Pos from, Pos to) {
this.from = from;
this.to = to;
}
@@ -101,8 +101,8 @@ class ScrollbarAnnotation extends Widget implements ClickHandler {
public void onClick(ClickEvent event) {
event.stopPropagation();
int line = from.getLine();
int h = to.getLine() - line;
int line = from.line();
int h = to.line() - line;
if (h > 5) {
// Map click inside of the annotation to the relative position
// within the region covered by the annotation.
@@ -111,7 +111,7 @@ class ScrollbarAnnotation extends Widget implements ClickHandler {
}
double y = cm.heightAtLine(line, "local");
double viewport = cm.getScrollInfo().getClientHeight();
double viewport = cm.getScrollInfo().clientHeight();
cm.setCursor(from);
cm.scrollTo(0, y - 0.5 * viewport);
cm.focus();

View File

@@ -75,8 +75,8 @@ import net.codemirror.lib.CodeMirror.LineClassWhere;
import net.codemirror.lib.CodeMirror.LineHandle;
import net.codemirror.lib.Configuration;
import net.codemirror.lib.KeyMap;
import net.codemirror.lib.LineCharacter;
import net.codemirror.lib.ModeInjector;
import net.codemirror.lib.Pos;
import java.util.ArrayList;
import java.util.Collections;
@@ -294,10 +294,10 @@ public class SideBySide2 extends Screen {
if (cm.lineAtHeight(height - 20) < line) {
cm.scrollToY(cm.heightAtLine(line, "local") - 0.5 * height);
}
cm.setCursor(LineCharacter.create(line));
cm.setCursor(Pos.create(line));
cm.focus();
} else {
cmA.setCursor(LineCharacter.create(0));
cmA.setCursor(Pos.create(0));
cmA.focus();
}
if (Gerrit.isSignedIn() && prefs.autoReview()) {
@@ -393,19 +393,19 @@ public class SideBySide2 extends Screen {
.on("Space", new Runnable() {
@Override
public void run() {
CodeMirror.handleVimKey(cm, "<C-d>");
cm.vim().handleKey("<C-d>");
}
})
.on("Shift-Space", new Runnable() {
@Override
public void run() {
CodeMirror.handleVimKey(cm, "<C-u>");
cm.vim().handleKey("<C-u>");
}
})
.on("Ctrl-F", new Runnable() {
@Override
public void run() {
CodeMirror.handleVimKey(cm, "/");
cm.vim().handleKey("/");
}
})
.on("Ctrl-A", new Runnable() {
@@ -424,10 +424,8 @@ public class SideBySide2 extends Screen {
private InsertCommentBubble bubble;
@Override
public void handle(CodeMirror cm, LineCharacter anchor, LineCharacter head) {
if (anchor == head
|| (anchor.getLine() == head.getLine()
&& anchor.getCh() == head.getCh())) {
public void handle(CodeMirror cm, Pos anchor, Pos head) {
if (anchor.equals(head)) {
if (bubble != null) {
bubble.setVisible(false);
}
@@ -440,10 +438,10 @@ public class SideBySide2 extends Screen {
bubble.position(cm.charCoords(head, "local"));
}
private void init(LineCharacter anchor) {
private void init(Pos anchor) {
bubble = new InsertCommentBubble(commentManager, cm);
add(bubble);
cm.addWidget(anchor, bubble.getElement(), false);
cm.addWidget(anchor, bubble.getElement());
}
};
}
@@ -551,8 +549,8 @@ public class SideBySide2 extends Screen {
diffTable.addStyleName(DiffTable.style.showLineNumbers());
}
cmA = newCM(diff.meta_a(), diff.text_a(), DisplaySide.A, diffTable.cmA);
cmB = newCM(diff.meta_b(), diff.text_b(), DisplaySide.B, diffTable.cmB);
cmA = newCM(diff.meta_a(), diff.text_a(), diffTable.cmA).side(DisplaySide.A);
cmB = newCM(diff.meta_b(), diff.text_b(), diffTable.cmB).side(DisplaySide.B);
chunkManager = new ChunkManager(this, cmA, cmB, diffTable.scrollbar);
skipManager = new SkipManager(this, commentManager);
@@ -560,8 +558,8 @@ public class SideBySide2 extends Screen {
columnMarginB = DOM.createDiv();
columnMarginA.setClassName(DiffTable.style.columnMargin());
columnMarginB.setClassName(DiffTable.style.columnMargin());
cmA.getMoverElement().appendChild(columnMarginA);
cmB.getMoverElement().appendChild(columnMarginB);
cmA.mover().appendChild(columnMarginA);
cmB.mover().appendChild(columnMarginB);
if (prefs.renderEntireFile() && !canEnableRenderEntireFile(prefs)) {
// CodeMirror is too slow to layout an entire huge file.
@@ -636,18 +634,14 @@ public class SideBySide2 extends Screen {
private CodeMirror newCM(
DiffInfo.FileMeta meta,
String contents,
DisplaySide side,
Element parent) {
String mode = fileSize == FileSize.SMALL
? getContentType(meta)
: null;
return CodeMirror.create(side, parent, Configuration.create()
return CodeMirror.create(parent, Configuration.create()
.set("readOnly", true)
.set("cursorBlinkRate", 0)
.set("cursorHeight", 0.85)
.set("lineNumbers", prefs.showLineNumbers())
.set("tabSize", prefs.tabSize())
.set("mode", mode)
.set("mode", fileSize == FileSize.SMALL ? getContentType(meta) : null)
.set("lineWrapping", false)
.set("scrollbarStyle", "overlay")
.set("styleSelectedText", true)
@@ -706,7 +700,7 @@ public class SideBySide2 extends Screen {
e.appendChild(pre);
}
cmB.getMeasureElement().appendChild(p);
cmB.measure().appendChild(p);
lineHeightPx = ((double) p.getOffsetHeight()) / lines;
p.removeFromParent();
}
@@ -724,11 +718,11 @@ public class SideBySide2 extends Screen {
e.getStyle().setDisplay(Style.Display.INLINE_BLOCK);
e.setInnerText(s.toString());
cmA.getMeasureElement().appendChild(e);
cmA.measure().appendChild(e);
double a = ((double) e.getOffsetWidth()) / len;
e.removeFromParent();
cmB.getMeasureElement().appendChild(e);
cmB.measure().appendChild(e);
double b = ((double) e.getOffsetWidth()) / len;
e.removeFromParent();
charWidthPx = Math.max(a, b);
@@ -817,10 +811,10 @@ public class SideBySide2 extends Screen {
private void clearActiveLine(CodeMirror cm) {
if (cm.hasActiveLine()) {
LineHandle activeLine = cm.getActiveLine();
LineHandle activeLine = cm.activeLine();
cm.removeLineClass(activeLine,
LineClassWhere.WRAP, DiffTable.style.activeLine());
cm.setActiveLine(null);
cm.activeLine(null);
}
}
@@ -840,22 +834,22 @@ public class SideBySide2 extends Screen {
operation(new Runnable() {
@Override
public void run() {
LineHandle handle = cm.getLineHandleVisualStart(
cm.getCursor("end").getLine());
if (cm.hasActiveLine() && cm.getActiveLine().equals(handle)) {
LineHandle handle =
cm.getLineHandleVisualStart(cm.getCursor("end").line());
if (cm.hasActiveLine() && cm.activeLine().equals(handle)) {
return;
}
clearActiveLine(cm);
clearActiveLine(other);
cm.setActiveLine(handle);
cm.activeLine(handle);
cm.addLineClass(
handle, LineClassWhere.WRAP, DiffTable.style.activeLine());
LineOnOtherInfo info =
lineOnOther(cm.side(), cm.getLineNumber(handle));
if (info.isAligned()) {
LineHandle oLineHandle = other.getLineHandle(info.getLine());
other.setActiveLine(oLineHandle);
other.activeLine(oLineHandle);
other.addLineClass(oLineHandle, LineClassWhere.WRAP,
DiffTable.style.activeLine());
}
@@ -878,8 +872,8 @@ public class SideBySide2 extends Screen {
&& !clickEvent.getCtrlKey()
&& !clickEvent.getShiftKey()) {
if (!(cm.hasActiveLine() &&
cm.getLineNumber(cm.getActiveLine()) == line)) {
cm.setCursor(LineCharacter.create(line));
cm.getLineNumber(cm.activeLine()) == line)) {
cm.setCursor(Pos.create(line));
}
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
@@ -929,9 +923,9 @@ public class SideBySide2 extends Screen {
@Override
public void run() {
if (cmSrc.hasActiveLine()) {
cmDst.setCursor(LineCharacter.create(lineOnOther(
cmDst.setCursor(Pos.create(lineOnOther(
sideSrc,
cmSrc.getLineNumber(cmSrc.getActiveLine())).getLine()));
cmSrc.getLineNumber(cmSrc.activeLine())).getLine()));
}
cmDst.focus();
}
@@ -942,8 +936,8 @@ public class SideBySide2 extends Screen {
return new Runnable() {
@Override
public void run() {
if (cm.hasVimSearchHighlight()) {
CodeMirror.handleVimKey(cm, "N");
if (cm.vim().hasSearchHighlight()) {
cm.vim().handleKey("N");
} else {
commentManager.commentNav(cm, Direction.NEXT).run();
}
@@ -955,8 +949,8 @@ public class SideBySide2 extends Screen {
return new Runnable() {
@Override
public void run() {
if (cm.hasVimSearchHighlight()) {
CodeMirror.handleVimKey(cm, "n");
if (cm.vim().hasSearchHighlight()) {
cm.vim().handleKey("n");
} else {
chunkManager.diffChunkNav(cm, Direction.NEXT).run();
}

View File

@@ -30,6 +30,7 @@ import com.google.gwt.user.client.ui.HTMLPanel;
import net.codemirror.lib.CodeMirror;
import net.codemirror.lib.Configuration;
import net.codemirror.lib.LineWidget;
import net.codemirror.lib.Pos;
import net.codemirror.lib.TextMarker;
import net.codemirror.lib.TextMarker.FromTo;
@@ -95,8 +96,8 @@ class SkipBar extends Composite {
}
textMarker = cm.markText(
CodeMirror.pos(start, 0),
CodeMirror.pos(end),
Pos.create(start, 0),
Pos.create(end),
Configuration.create()
.set("collapsed", true)
.set("inclusiveLeft", true)
@@ -137,9 +138,9 @@ class SkipBar extends Composite {
private void expandSideBefore(int cnt) {
FromTo range = textMarker.find();
int oldStart = range.getFrom().getLine();
int oldStart = range.from().line();
int newStart = oldStart + cnt;
int end = range.getTo().getLine();
int end = range.to().line();
clearMarkerAndWidget();
collapse(newStart, end, true);
updateSelection();
@@ -152,8 +153,8 @@ class SkipBar extends Composite {
private void expandAfter() {
FromTo range = textMarker.find();
int start = range.getFrom().getLine();
int oldEnd = range.getTo().getLine();
int start = range.from().line();
int oldEnd = range.to().line();
int newEnd = oldEnd - NUM_ROWS_TO_EXPAND;
boolean attach = start == 0;
if (attach) {
@@ -168,7 +169,7 @@ class SkipBar extends Composite {
private void updateSelection() {
if (cm.somethingSelected()) {
FromTo sel = cm.getSelectedRange();
cm.setSelection(sel.getFrom(), sel.getTo());
cm.setSelection(sel.from(), sel.to());
}
}

View File

@@ -32,153 +32,146 @@ public class CodeMirror extends JavaScriptObject {
Loader.initLibrary(cb);
}
public static native CodeMirror create(
DisplaySide side,
Element parent,
Configuration cfg) /*-{
var m = $wnd.CodeMirror(parent, cfg);
m._sbs2_side = side;
return m;
public static native CodeMirror create(Element p, Configuration cfg) /*-{
return $wnd.CodeMirror(p, cfg);
}-*/;
public static CodeMirror create(Element parent, Configuration cfg) {
return create(null, parent, cfg);
}
public final native void setOption(String option, boolean value) /*-{
this.setOption(option, value);
this.setOption(option, value)
}-*/;
public final native void setOption(String option, double value) /*-{
this.setOption(option, value);
this.setOption(option, value)
}-*/;
public final native void setOption(String option, String value) /*-{
this.setOption(option, value);
this.setOption(option, value)
}-*/;
public final native void setOption(String option, JavaScriptObject val) /*-{
this.setOption(option, val);
this.setOption(option, val)
}-*/;
public final native String getStringOption(String o) /*-{ return this.getOption(o) }-*/;
public final native void setValue(String v) /*-{ this.setValue(v); }-*/;
public final native void setWidth(double w) /*-{ this.setSize(w, null); }-*/;
public final native void setWidth(String w) /*-{ this.setSize(w, null); }-*/;
public final native void setHeight(double h) /*-{ this.setSize(null, h); }-*/;
public final native void setHeight(String h) /*-{ this.setSize(null, h); }-*/;
public final native String getValue() /*-{ return this.getValue() }-*/;
public final native void setValue(String v) /*-{ this.setValue(v) }-*/;
public final native void setWidth(double w) /*-{ this.setSize(w, null) }-*/;
public final native void setWidth(String w) /*-{ this.setSize(w, null) }-*/;
public final native void setHeight(double h) /*-{ this.setSize(null, h) }-*/;
public final native void setHeight(String h) /*-{ this.setSize(null, h) }-*/;
public final native String getLine(int n) /*-{ return this.getLine(n) }-*/;
public final native double barHeight() /*-{ return this.display.barHeight }-*/;
public final native double barWidth() /*-{ return this.display.barWidth }-*/;
public final native int lastLine() /*-{ return this.lastLine() }-*/;
public final native void refresh() /*-{ this.refresh() }-*/;
public final native void refresh() /*-{ this.refresh(); }-*/;
public final native Element getWrapperElement() /*-{ return this.getWrapperElement(); }-*/;
public final native TextMarker markText(LineCharacter from, LineCharacter to,
public final native TextMarker markText(Pos from, Pos to,
Configuration options) /*-{
return this.markText(from, to, options);
return this.markText(from, to, options)
}-*/;
public enum LineClassWhere {
TEXT, BACKGROUND, WRAP
TEXT { @Override String value() { return "text"; } },
BACKGROUND { @Override String value() { return "background"; } },
WRAP { @Override String value() { return "wrap"; } };
abstract String value();
}
public final void addLineClass(int line, LineClassWhere where,
String className) {
addLineClassNative(line, where.name().toLowerCase(), className);
addLineClassNative(line, where.value(), className);
}
private final native void addLineClassNative(int line, String where,
String lineClass) /*-{
this.addLineClass(line, where, lineClass);
this.addLineClass(line, where, lineClass)
}-*/;
public final void addLineClass(LineHandle line, LineClassWhere where,
String className) {
addLineClassNative(line, where.name().toLowerCase(), className);
addLineClassNative(line, where.value(), className);
}
private final native void addLineClassNative(LineHandle line, String where,
String lineClass) /*-{
this.addLineClass(line, where, lineClass);
this.addLineClass(line, where, lineClass)
}-*/;
public final void removeLineClass(int line, LineClassWhere where,
String className) {
removeLineClassNative(line, where.name().toLowerCase(), className);
removeLineClassNative(line, where.value(), className);
}
private final native void removeLineClassNative(int line, String where,
String lineClass) /*-{
this.removeLineClass(line, where, lineClass);
this.removeLineClass(line, where, lineClass)
}-*/;
public final void removeLineClass(LineHandle line, LineClassWhere where,
String className) {
removeLineClassNative(line, where.name().toLowerCase(), className);
removeLineClassNative(line, where.value(), className);
}
private final native void removeLineClassNative(LineHandle line, String where,
String lineClass) /*-{
this.removeLineClass(line, where, lineClass);
this.removeLineClass(line, where, lineClass)
}-*/;
public final native void addWidget(LineCharacter pos, Element node,
boolean scrollIntoView) /*-{
this.addWidget(pos, node, scrollIntoView);
public final native void addWidget(Pos pos, Element node) /*-{
this.addWidget(pos, node, false)
}-*/;
public final native LineWidget addLineWidget(int line, Element node,
Configuration options) /*-{
return this.addLineWidget(line, node, options);
return this.addLineWidget(line, node, options)
}-*/;
public final native int lineAtHeight(double height) /*-{
return this.lineAtHeight(height);
return this.lineAtHeight(height)
}-*/;
public final native int lineAtHeight(double height, String mode) /*-{
return this.lineAtHeight(height, mode);
return this.lineAtHeight(height, mode)
}-*/;
public final native double heightAtLine(int line) /*-{
return this.heightAtLine(line);
return this.heightAtLine(line)
}-*/;
public final native double heightAtLine(int line, String mode) /*-{
return this.heightAtLine(line, mode);
return this.heightAtLine(line, mode)
}-*/;
public final native Rect charCoords(LineCharacter pos, String mode) /*-{
return this.charCoords(pos, mode);
public final native Rect charCoords(Pos pos, String mode) /*-{
return this.charCoords(pos, mode)
}-*/;
public final native CodeMirrorDoc getDoc() /*-{
return this.getDoc();
return this.getDoc()
}-*/;
public final native void scrollTo(double x, double y) /*-{
this.scrollTo(x, y);
this.scrollTo(x, y)
}-*/;
public final native void scrollToY(double y) /*-{
this.scrollTo(null, y);
this.scrollTo(null, y)
}-*/;
public final native ScrollInfo getScrollInfo() /*-{
return this.getScrollInfo();
return this.getScrollInfo()
}-*/;
public final native Viewport getViewport() /*-{
return this.getViewport();
return this.getViewport()
}-*/;
public final native void operation(Runnable thunk) /*-{
this.operation(function() {
thunk.@java.lang.Runnable::run()();
});
})
}-*/;
public final native void off(String event, RegisteredHandler h) /*-{
@@ -194,120 +187,112 @@ public class CodeMirror extends JavaScriptObject {
public final native void on(String event, EventHandler handler) /*-{
this.on(event, $entry(function(cm, e) {
handler.@net.codemirror.lib.CodeMirror.EventHandler::handle(
Lnet/codemirror/lib/CodeMirror;Lcom/google/gwt/dom/client/NativeEvent;)(cm, e);
}));
Lnet/codemirror/lib/CodeMirror;
Lcom/google/gwt/dom/client/NativeEvent;)(cm, e);
}))
}-*/;
public final native void on(String event, RenderLineHandler handler) /*-{
this.on(event, $entry(function(cm, h, ele) {
this.on(event, $entry(function(cm, h, e) {
handler.@net.codemirror.lib.CodeMirror.RenderLineHandler::handle(
Lnet/codemirror/lib/CodeMirror;Lnet/codemirror/lib/CodeMirror$LineHandle;
Lcom/google/gwt/dom/client/Element;)(cm, h, ele);
}));
Lnet/codemirror/lib/CodeMirror;
Lnet/codemirror/lib/CodeMirror$LineHandle;
Lcom/google/gwt/dom/client/Element;)(cm, h, e);
}))
}-*/;
public final native void on(String event, GutterClickHandler handler) /*-{
this.on(event, $entry(function(cm, l, g, e) {
handler.@net.codemirror.lib.CodeMirror.GutterClickHandler::handle(
Lnet/codemirror/lib/CodeMirror;ILjava/lang/String;
Lnet/codemirror/lib/CodeMirror;
I
Ljava/lang/String;
Lcom/google/gwt/dom/client/NativeEvent;)(cm, l, g, e);
}));
}))
}-*/;
public final native void on(String event, BeforeSelectionChangeHandler handler) /*-{
this.on(event, $entry(function(cm, o) {
var e = o.ranges[o.ranges.length-1];
handler.@net.codemirror.lib.CodeMirror.BeforeSelectionChangeHandler::handle(
Lnet/codemirror/lib/CodeMirror;Lnet/codemirror/lib/LineCharacter;
Lnet/codemirror/lib/LineCharacter;)(cm,e.anchor,e.head);
}));
Lnet/codemirror/lib/CodeMirror;
Lnet/codemirror/lib/Pos;
Lnet/codemirror/lib/Pos;)(cm, e.anchor, e.head);
}))
}-*/;
public final native LineCharacter getCursor() /*-{
return this.getCursor();
}-*/;
public final native LineCharacter getCursor(String start) /*-{
return this.getCursor(start);
public final native void setCursor(Pos p) /*-{ this.setCursor(p) }-*/;
public final native Pos getCursor() /*-{ return this.getCursor() }-*/;
public final native Pos getCursor(String start) /*-{
return this.getCursor(start)
}-*/;
public final FromTo getSelectedRange() {
return FromTo.create(getCursor("start"), getCursor("end"));
}
public final native void setSelection(LineCharacter anchor) /*-{
this.setSelection(anchor);
}-*/;
public final native void setSelection(LineCharacter anchor, LineCharacter head) /*-{
this.setSelection(anchor, head);
}-*/;
public final native void setCursor(LineCharacter lineCh) /*-{
this.setCursor(lineCh);
public final native void setSelection(Pos p) /*-{ this.setSelection(p) }-*/;
public final native void setSelection(Pos anchor, Pos head) /*-{
this.setSelection(anchor, head)
}-*/;
public final native boolean somethingSelected() /*-{
return this.somethingSelected();
return this.somethingSelected()
}-*/;
public final native boolean hasActiveLine() /*-{
return !!this.state.activeLine;
return !!this.state.activeLine
}-*/;
public final native LineHandle getActiveLine() /*-{
return this.state.activeLine;
public final native LineHandle activeLine() /*-{
return this.state.activeLine
}-*/;
public final native void setActiveLine(LineHandle line) /*-{
this.state.activeLine = line;
public final native void activeLine(LineHandle line) /*-{
this.state.activeLine = line
}-*/;
public final native void addKeyMap(KeyMap map) /*-{ this.addKeyMap(map); }-*/;
public final native void removeKeyMap(KeyMap map) /*-{ this.removeKeyMap(map); }-*/;
public static final native LineCharacter pos(int line, int ch) /*-{
return $wnd.CodeMirror.Pos(line, ch);
}-*/;
public static final native LineCharacter pos(int line) /*-{
return $wnd.CodeMirror.Pos(line);
}-*/;
public final native void addKeyMap(KeyMap map) /*-{ this.addKeyMap(map) }-*/;
public final native void removeKeyMap(KeyMap map) /*-{ this.removeKeyMap(map) }-*/;
public final native LineHandle getLineHandle(int line) /*-{
return this.getLineHandle(line);
return this.getLineHandle(line)
}-*/;
public final native LineHandle getLineHandleVisualStart(int line) /*-{
return this.getLineHandleVisualStart(line);
return this.getLineHandleVisualStart(line)
}-*/;
public final native int getLineNumber(LineHandle handle) /*-{
return this.getLineNumber(handle);
return this.getLineNumber(handle)
}-*/;
public final native void focus() /*-{
this.focus();
this.focus()
}-*/;
public final native Element getWrapperElement() /*-{
return this.getWrapperElement()
}-*/;
public final native Element getGutterElement() /*-{
return this.getGutterElement();
return this.getGutterElement()
}-*/;
public final native Element getSizer() /*-{
return this.display.sizer;
public final native Element sizer() /*-{
return this.display.sizer
}-*/;
public final native Element getMoverElement() /*-{
return this.display.mover;
public final native Element mover() /*-{
return this.display.mover
}-*/;
public final native Element getMeasureElement() /*-{
return this.display.measure;
public final native Element measure() /*-{
return this.display.measure
}-*/;
public final native Element getScrollbarV() /*-{
return this.display.scrollbarV;
public final native Element scrollbarV() /*-{
return this.display.scrollbarV
}-*/;
public static final native KeyMap cloneKeyMap(String name) /*-{
@@ -320,36 +305,31 @@ public class CodeMirror extends JavaScriptObject {
}-*/;
public final native void execCommand(String cmd) /*-{
this.execCommand(cmd);
this.execCommand(cmd)
}-*/;
public static final native void addKeyMap(String name, KeyMap km) /*-{
$wnd.CodeMirror.keyMap[name] = km;
$wnd.CodeMirror.keyMap[name] = km
}-*/;
public static final native void handleVimKey(CodeMirror cm, String key) /*-{
$wnd.CodeMirror.Vim.handleKey(cm, key);
}-*/;
public static final native void mapVimKey(String alias, String actual) /*-{
$wnd.CodeMirror.Vim.map(alias, actual);
}-*/;
public final native boolean hasVimSearchHighlight() /*-{
return this.state.vim && this.state.vim.searchState_ &&
!!this.state.vim.searchState_.getOverlay();
public final native Vim vim() /*-{
return this;
}-*/;
public final native DisplaySide side() /*-{ return this._sbs2_side }-*/;
public final native CodeMirror side(DisplaySide side) /*-{
this._sbs2_side = side;
return this;
}-*/;
protected CodeMirror() {
}
public static class Viewport extends JavaScriptObject {
public final native int getFrom() /*-{ return this.from; }-*/;
public final native int getTo() /*-{ return this.to; }-*/;
public final native int from() /*-{ return this.from }-*/;
public final native int to() /*-{ return this.to }-*/;
public final boolean contains(int line) {
return getFrom() <= line && line < getTo();
return from() <= line && line < to();
}
protected Viewport() {
@@ -380,10 +360,6 @@ public class CodeMirror extends JavaScriptObject {
}
public interface BeforeSelectionChangeHandler {
public void handle(CodeMirror instance, LineCharacter anchor, LineCharacter head);
public void handle(CodeMirror instance, Pos anchor, Pos head);
}
public final native String getValue() /*-{
return this.getValue();
}-*/;
}

View File

@@ -20,11 +20,11 @@ import com.google.gwt.core.client.JavaScriptObject;
public class CodeMirrorDoc extends JavaScriptObject {
public final native void replaceRange(String replacement,
LineCharacter from, LineCharacter to) /*-{
Pos from, Pos to) /*-{
this.replaceRange(replacement, from, to);
}-*/;
public final native void insertText(String insertion, LineCharacter at) /*-{
public final native void insertText(String insertion, Pos at) /*-{
this.replaceRange(insertion, at);
}-*/;

View File

@@ -1,44 +0,0 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package net.codemirror.lib;
import com.google.gwt.core.client.JavaScriptObject;
/** {line, ch} objects used within CodeMirror. */
public class LineCharacter extends JavaScriptObject {
public static LineCharacter create(int line, int ch) {
return createImpl(line, ch);
}
public static LineCharacter create(int line) {
return createImpl(line, 0);
}
private static LineCharacter createImpl(int line, int ch) {
LineCharacter lineCh = createObject().cast();
lineCh.setLine(line);
lineCh.setCh(ch);
return lineCh;
}
public final native void setLine(int line) /*-{ this.line = line; }-*/;
public final native void setCh(int ch) /*-{ this.ch = ch; }-*/;
public final native int getLine() /*-{ return this.line; }-*/;
public final native int getCh() /*-{ return this.ch; }-*/;
protected LineCharacter() {
}
}

View File

@@ -18,17 +18,13 @@ import com.google.gwt.core.client.JavaScriptObject;
/** LineWidget objects used within CodeMirror. */
public class LineWidget extends JavaScriptObject {
public static LineWidget create() {
return createObject().cast();
}
public final native void clear() /*-{ this.clear(); }-*/;
public final native void changed() /*-{ this.changed(); }-*/;
public final native void clear() /*-{ this.clear() }-*/;
public final native void changed() /*-{ this.changed() }-*/;
public final native void onRedraw(Runnable thunk) /*-{
this.on("redraw", $entry(function() {
thunk.@java.lang.Runnable::run()();
}));
}))
}-*/;
public final native void onFirstRedraw(Runnable thunk) /*-{

View File

@@ -41,7 +41,7 @@ class Loader {
injectScript(Lib.I.js().getSafeUri(), new GerritCallback<Void>(){
@Override
public void onSuccess(Void result) {
initVimKeys();
Vim.initKeyMap();
cb.onSuccess(null);
}
});
@@ -87,28 +87,6 @@ class Loader {
.cast();
}
private static void initVimKeys() {
// TODO: Better custom keybindings, remove temporary navigation hacks.
KeyMap km = CodeMirror.cloneKeyMap("vim");
for (String s : new String[] {
"A", "C", "I", "O", "R", "U",
"Ctrl-C", "Ctrl-O", "Ctrl-P", "Ctrl-S",
"Ctrl-F", "Ctrl-B", "Ctrl-R"}) {
km.remove(s);
}
for (int i = 0; i <= 9; i++) {
km.remove("Ctrl-" + i);
}
CodeMirror.addKeyMap("vim_ro", km);
CodeMirror.mapVimKey("j", "gj");
CodeMirror.mapVimKey("k", "gk");
CodeMirror.mapVimKey("Down", "gj");
CodeMirror.mapVimKey("Up", "gk");
CodeMirror.mapVimKey("<PageUp>", "<C-u>");
CodeMirror.mapVimKey("<PageDown>", "<C-d>");
}
private static void error(Exception e) {
Logger log = Logger.getLogger("net.codemirror");
log.log(Level.SEVERE, "Cannot load portions of CodeMirror", e);

View File

@@ -0,0 +1,41 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package net.codemirror.lib;
import com.google.gwt.core.client.JavaScriptObject;
/** Pos (or {line, ch}) objects used within CodeMirror. */
public class Pos extends JavaScriptObject {
public static final native Pos create(int line) /*-{
return $wnd.CodeMirror.Pos(line)
}-*/;
public static final native Pos create(int line, int ch) /*-{
return $wnd.CodeMirror.Pos(line, ch)
}-*/;
public final native void line(int l) /*-{ this.line = l }-*/;
public final native void ch(int c) /*-{ this.ch = c }-*/;
public final native int line() /*-{ return this.line }-*/;
public final native int ch() /*-{ return this.ch || 0 }-*/;
public final boolean equals(Pos o) {
return this == o || (line() == o.line() && ch() == o.ch());
}
protected Pos() {
}
}

View File

@@ -18,20 +18,20 @@ import com.google.gwt.core.client.JavaScriptObject;
/** Returned by {@link CodeMirror#getScrollInfo()}. */
public class ScrollInfo extends JavaScriptObject {
public final native double getLeft() /*-{ return this.left; }-*/;
public final native double getTop() /*-{ return this.top; }-*/;
public final native double left() /*-{ return this.left }-*/;
public final native double top() /*-{ return this.top }-*/;
/**
* Pixel height of the full content being scrolled. This may only be an
* estimate given by CodeMirror. Line widgets further down in the document may
* not be measured, so line heights can be incorrect until drawn.
*/
public final native double getHeight() /*-{ return this.height; }-*/;
public final native double getWidth() /*-{ return this.width; }-*/;
public final native double height() /*-{ return this.height }-*/;
public final native double width() /*-{ return this.width }-*/;
/** Visible height of the viewport, excluding scrollbars. */
public final native double getClientHeight() /*-{ return this.clientHeight; }-*/;
public final native double getClientWidth() /*-{ return this.clientWidth; }-*/;
public final native double clientHeight() /*-{ return this.clientHeight }-*/;
public final native double clientWidth() /*-{ return this.clientWidth }-*/;
protected ScrollInfo() {
}

View File

@@ -19,10 +19,6 @@ import com.google.gwt.core.client.JavaScriptObject;
/** Object that represents a text marker within CodeMirror */
public class TextMarker extends JavaScriptObject {
public static TextMarker create() {
return createObject().cast();
}
public final native void clear() /*-{ this.clear(); }-*/;
public final native void changed() /*-{ this.changed(); }-*/;
public final native FromTo find() /*-{ return this.find(); }-*/;
@@ -33,24 +29,21 @@ public class TextMarker extends JavaScriptObject {
}
public static class FromTo extends JavaScriptObject {
public static FromTo create(LineCharacter from, LineCharacter to) {
FromTo fromTo = createObject().cast();
fromTo.setFrom(from);
fromTo.setTo(to);
return fromTo;
}
public static final native FromTo create(Pos f, Pos t) /*-{
return {from: f, to: t}
}-*/;
public static FromTo create(CommentRange range) {
return create(
LineCharacter.create(range.start_line() - 1, range.start_character()),
LineCharacter.create(range.end_line() - 1, range.end_character()));
Pos.create(range.start_line() - 1, range.start_character()),
Pos.create(range.end_line() - 1, range.end_character()));
}
public final native LineCharacter getFrom() /*-{ return this.from; }-*/;
public final native LineCharacter getTo() /*-{ return this.to; }-*/;
public final native Pos from() /*-{ return this.from }-*/;
public final native Pos to() /*-{ return this.to }-*/;
public final native void setFrom(LineCharacter from) /*-{ this.from = from; }-*/;
public final native void setTo(LineCharacter to) /*-{ this.to = to; }-*/;
public final native void from(Pos f) /*-{ this.from = f }-*/;
public final native void to(Pos t) /*-{ this.to = t }-*/;
protected FromTo() {
}

View File

@@ -0,0 +1,64 @@
// Copyright (C) 2014 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package net.codemirror.lib;
import com.google.gwt.core.client.JavaScriptObject;
/**
* Glue around the Vim emulation for {@link CodeMirror}.
*
* As an instance {@code this} is actually the {@link CodeMirror} object. Class
* Vim is providing a new namespace for Vim related methods that are associated
* with an editor.
*/
public class Vim extends JavaScriptObject {
static void initKeyMap() {
// TODO: Better custom keybindings, remove temporary navigation hacks.
KeyMap km = CodeMirror.cloneKeyMap("vim");
for (String s : new String[] {
"A", "C", "I", "O", "R", "U",
"Ctrl-C", "Ctrl-O", "Ctrl-P", "Ctrl-S",
"Ctrl-F", "Ctrl-B", "Ctrl-R"}) {
km.remove(s);
}
for (int i = 0; i <= 9; i++) {
km.remove("Ctrl-" + i);
}
CodeMirror.addKeyMap("vim_ro", km);
mapKey("j", "gj");
mapKey("k", "gk");
mapKey("Down", "gj");
mapKey("Up", "gk");
mapKey("<PageUp>", "<C-u>");
mapKey("<PageDown>", "<C-d>");
}
public static final native void mapKey(String alias, String actual) /*-{
$wnd.CodeMirror.Vim.map(alias, actual)
}-*/;
public final native void handleKey(String key) /*-{
$wnd.CodeMirror.Vim.handleKey(this, key)
}-*/;
public final native boolean hasSearchHighlight() /*-{
var v = this.state.vim;
return v && v.searchState_ && !!v.searchState_.getOverlay();
}-*/;
protected Vim() {
}
}

View File

@@ -22,7 +22,7 @@ import com.google.gwt.core.client.JsArrayString;
import com.googlecode.gwt.test.GwtModule;
import com.googlecode.gwt.test.GwtTest;
import net.codemirror.lib.LineCharacter;
import net.codemirror.lib.Pos;
import org.junit.Before;
import org.junit.Ignore;
@@ -35,8 +35,8 @@ import org.junit.Test;
public class EditIteratorTest extends GwtTest {
private JsArrayString lines;
private void assertLineChsEqual(LineCharacter a, LineCharacter b) {
assertEquals(a.getLine() + "," + a.getCh(), b.getLine() + "," + b.getCh());
private void assertLineChsEqual(Pos a, Pos b) {
assertEquals(a.line() + "," + a.ch(), b.line() + "," + b.ch());
}
@Before
@@ -50,57 +50,57 @@ public class EditIteratorTest extends GwtTest {
@Test
public void testNegativeAdvance() {
EditIterator i = new EditIterator(lines, 0);
assertLineChsEqual(LineCharacter.create(1, 1), i.advance(5));
assertLineChsEqual(LineCharacter.create(0, 3), i.advance(-2));
assertLineChsEqual(Pos.create(1, 1), i.advance(5));
assertLineChsEqual(Pos.create(0, 3), i.advance(-2));
}
@Test
public void testNoAdvance() {
EditIterator iter = new EditIterator(lines, 0);
assertLineChsEqual(LineCharacter.create(0), iter.advance(0));
assertLineChsEqual(Pos.create(0), iter.advance(0));
}
@Test
public void testSimpleAdvance() {
EditIterator iter = new EditIterator(lines, 0);
assertLineChsEqual(LineCharacter.create(0, 1), iter.advance(1));
assertLineChsEqual(Pos.create(0, 1), iter.advance(1));
}
@Test
public void testEndsBeforeNewline() {
EditIterator iter = new EditIterator(lines, 0);
assertLineChsEqual(LineCharacter.create(0, 3), iter.advance(3));
assertLineChsEqual(Pos.create(0, 3), iter.advance(3));
}
@Test
public void testEndsOnNewline() {
EditIterator iter = new EditIterator(lines, 0);
assertLineChsEqual(LineCharacter.create(1), iter.advance(4));
assertLineChsEqual(Pos.create(1), iter.advance(4));
}
@Test
public void testAcrossNewline() {
EditIterator iter = new EditIterator(lines, 0);
assertLineChsEqual(LineCharacter.create(1, 1), iter.advance(5));
assertLineChsEqual(Pos.create(1, 1), iter.advance(5));
}
@Test
public void testContinueFromBeforeNewline() {
EditIterator iter = new EditIterator(lines, 0);
iter.advance(3);
assertLineChsEqual(LineCharacter.create(2, 2), iter.advance(7));
assertLineChsEqual(Pos.create(2, 2), iter.advance(7));
}
@Test
public void testContinueFromAfterNewline() {
EditIterator iter = new EditIterator(lines, 0);
iter.advance(4);
assertLineChsEqual(LineCharacter.create(2, 2), iter.advance(6));
assertLineChsEqual(Pos.create(2, 2), iter.advance(6));
}
@Test
public void testAcrossMultipleLines() {
EditIterator iter = new EditIterator(lines, 0);
assertLineChsEqual(LineCharacter.create(2, 2), iter.advance(10));
assertLineChsEqual(Pos.create(2, 2), iter.advance(10));
}
}