Add skipping of common context to CodeMirrorDemo.
Added SkipBar, which handles collapsing and expanding of common text that is longer than the preferred context. Added supporting CodeMirror wrappers. Removed unused addon foldcode.js. Fixed to not create publishedMap if published is null. Change-Id: Iabb3481f72529d2dec412de53416235af220d6d8
This commit is contained in:
@@ -19,10 +19,11 @@ import com.google.gerrit.client.changes.ChangeApi;
|
||||
import com.google.gerrit.client.changes.ChangeInfo;
|
||||
import com.google.gerrit.client.changes.CommentApi;
|
||||
import com.google.gerrit.client.changes.CommentInfo;
|
||||
import com.google.gerrit.client.diff.PaddingManager.LineWidgetElementPair;
|
||||
import com.google.gerrit.client.diff.DiffInfo.Region;
|
||||
import com.google.gerrit.client.diff.DiffInfo.Span;
|
||||
import com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo;
|
||||
import com.google.gerrit.client.diff.PaddingManager.LineWidgetElementPair;
|
||||
import com.google.gerrit.client.patches.SkippedLine;
|
||||
import com.google.gerrit.client.projects.ConfigInfoCache;
|
||||
import com.google.gerrit.client.rpc.CallbackGroup;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
@@ -31,6 +32,7 @@ import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
import com.google.gerrit.client.ui.CommentLinkProcessor;
|
||||
import com.google.gerrit.client.ui.Screen;
|
||||
import com.google.gerrit.common.changes.Side;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
@@ -53,6 +55,7 @@ import net.codemirror.lib.KeyMap;
|
||||
import net.codemirror.lib.LineCharacter;
|
||||
import net.codemirror.lib.LineWidget;
|
||||
import net.codemirror.lib.ModeInjector;
|
||||
import net.codemirror.lib.TextMarker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -84,6 +87,9 @@ public class CodeMirrorDemo extends Screen {
|
||||
private Map<LineHandle, CommentBox> lineActiveBoxMap;
|
||||
private Map<LineHandle, PublishedBox> lineLastPublishedBoxMap;
|
||||
private Map<LineHandle, PaddingManager> linePaddingManagerMap;
|
||||
private List<SkippedLine> skips;
|
||||
private Map<LineHandle, Integer> hiddenSkipMap;
|
||||
private int context;
|
||||
|
||||
public CodeMirrorDemo(
|
||||
PatchSet.Id base,
|
||||
@@ -197,6 +203,7 @@ public class CodeMirrorDemo extends Screen {
|
||||
private void display(DiffInfo diffInfo) {
|
||||
cmA = displaySide(diffInfo.meta_a(), diffInfo.text_a(), diffTable.getCmA());
|
||||
cmB = displaySide(diffInfo.meta_b(), diffInfo.text_b(), diffTable.getCmB());
|
||||
skips = new ArrayList<SkippedLine>();
|
||||
render(diffInfo);
|
||||
initialBoxes = new ArrayList<CommentBox>();
|
||||
lineActiveBoxMap = new HashMap<LineHandle, CommentBox>();
|
||||
@@ -209,8 +216,10 @@ public class CodeMirrorDemo extends Screen {
|
||||
if (drafts != null) {
|
||||
renderDrafts();
|
||||
}
|
||||
renderSkips();
|
||||
published = null;
|
||||
drafts = null;
|
||||
skips = null;
|
||||
cmA.on("cursorActivity", updateActiveLine(cmA));
|
||||
cmB.on("cursorActivity", updateActiveLine(cmB));
|
||||
if (Gerrit.isSignedIn()) {
|
||||
@@ -253,6 +262,10 @@ public class CodeMirrorDemo extends Screen {
|
||||
}
|
||||
|
||||
private void render(DiffInfo diff) {
|
||||
AccountDiffPreference pref = Gerrit.getAccountDiffPreference();
|
||||
context = pref != null
|
||||
? pref.getContext()
|
||||
: AccountDiffPreference.DEFAULT_CONTEXT;
|
||||
JsArray<Region> regions = diff.content();
|
||||
mapper = new LineMapper();
|
||||
for (int i = 0; i < regions.length(); i++) {
|
||||
@@ -260,8 +273,17 @@ public class CodeMirrorDemo extends Screen {
|
||||
int origLineA = mapper.getLineA();
|
||||
int origLineB = mapper.getLineB();
|
||||
if (current.ab() != null) { // Common
|
||||
// TODO: Handle skips.
|
||||
mapper.appendCommon(current.ab().length());
|
||||
int length = current.ab().length();
|
||||
mapper.appendCommon(length);
|
||||
if (i == 0 && length > context) {
|
||||
skips.add(new SkippedLine(0, 0, length - context));
|
||||
} else if (i == regions.length() - 1 && length > context) {
|
||||
skips.add(new SkippedLine(origLineA + context, origLineB + context,
|
||||
length - context));
|
||||
} else if (length > 2 * context) {
|
||||
skips.add(new SkippedLine(origLineA + context, origLineB + context,
|
||||
length - 2 * context));
|
||||
}
|
||||
} else { // Insert, Delete or Edit
|
||||
JsArrayString currentA = current.a() == null ? EMPTY : current.a();
|
||||
JsArrayString currentB = current.b() == null ? EMPTY : current.b();
|
||||
@@ -418,6 +440,73 @@ public class CodeMirrorDemo extends Screen {
|
||||
}
|
||||
}
|
||||
|
||||
private void renderSkips() {
|
||||
hiddenSkipMap = new HashMap<LineHandle, Integer>();
|
||||
for (CommentBox box : initialBoxes) {
|
||||
List<SkippedLine> temp = new ArrayList<SkippedLine>();
|
||||
for (SkippedLine skip : skips) {
|
||||
CommentInfo info = box.getOriginal();
|
||||
int startLine = info.side() == Side.PARENT
|
||||
? skip.getStartA()
|
||||
: skip.getStartB();
|
||||
int boxLine = info.line();
|
||||
int deltaBefore = boxLine - startLine;
|
||||
int deltaAfter = startLine + skip.getSize() - boxLine;
|
||||
if (deltaBefore < 0 || deltaAfter < 0) {
|
||||
temp.add(skip);
|
||||
} else if (deltaBefore > context && deltaAfter > context) {
|
||||
SkippedLine before = new SkippedLine(
|
||||
skip.getStartA(), skip.getStartB(),
|
||||
skip.getSize() - deltaAfter - context);
|
||||
skip.incrementStart(deltaBefore + context);
|
||||
temp.add(before);
|
||||
temp.add(skip);
|
||||
} else if (deltaAfter > context) {
|
||||
skip.incrementStart(deltaBefore + context);
|
||||
temp.add(skip);
|
||||
} else if (deltaBefore > context) {
|
||||
skip.reduceSize(deltaAfter + context);
|
||||
temp.add(skip);
|
||||
}
|
||||
}
|
||||
skips = temp;
|
||||
}
|
||||
for (SkippedLine skip : skips) {
|
||||
SkipBar barA = renderSkipHelper(cmA, skip);
|
||||
SkipBar barB = renderSkipHelper(cmB, skip);
|
||||
SkipBar.link(barA, barB);
|
||||
}
|
||||
}
|
||||
|
||||
private SkipBar renderSkipHelper(CodeMirror cm, SkippedLine skip) {
|
||||
int size = skip.getSize();
|
||||
int markStart = cm == cmA ? skip.getStartA() - 1 : skip.getStartB() - 1;
|
||||
int markEnd = markStart + size;
|
||||
hiddenSkipMap.put(cm.getLineHandle(markEnd), size);
|
||||
SkipBar bar = new SkipBar(cm, hiddenSkipMap);
|
||||
diffTable.add(bar);
|
||||
TextMarker marker = cm.markText(
|
||||
CodeMirror.pos(markStart),
|
||||
CodeMirror.pos(markEnd),
|
||||
Configuration.create().set("collapsed", true));
|
||||
/**
|
||||
* TODO: Due to CodeMirror limitation, there's no way to make the first
|
||||
* line disappear completely. The current approach leaves an empty line
|
||||
* with line number "1" still showing, and CodeMirror doesn't like manually
|
||||
* setting the display of a line to "none". A workaround may be to use
|
||||
* inline widget for the first line and regular line widgets for others.
|
||||
*/
|
||||
boolean isZero = markStart == -1;
|
||||
Configuration config = Configuration.create()
|
||||
.set("coverGutter", true)
|
||||
.set("above", isZero);
|
||||
LineWidget widget = cm.addLineWidget(
|
||||
isZero ? markEnd + 1 : markStart, bar.getElement(), config);
|
||||
bar.setWidget(widget);
|
||||
bar.setMarker(marker, size);
|
||||
return bar;
|
||||
}
|
||||
|
||||
private CodeMirror otherCM(CodeMirror me) {
|
||||
return me == cmA ? cmB : cmA;
|
||||
}
|
||||
@@ -438,7 +527,7 @@ public class CodeMirrorDemo extends Screen {
|
||||
Configuration diffOpt = Configuration.create()
|
||||
.set("className", diffTable.style.diff())
|
||||
.set("readOnly", true);
|
||||
LineCharacter last = LineCharacter.create(0, 0);
|
||||
LineCharacter last = CodeMirror.pos(0, 0);
|
||||
for (int i = 0; i < edits.length(); i++) {
|
||||
Span span = edits.get(i);
|
||||
LineCharacter from = iter.advance(span.skip());
|
||||
@@ -447,7 +536,7 @@ public class CodeMirrorDemo extends Screen {
|
||||
if (last.getLine() == fromLine) {
|
||||
cm.markText(last, from, intralineBgOpt);
|
||||
} else {
|
||||
cm.markText(LineCharacter.create(fromLine, 0), from, intralineBgOpt);
|
||||
cm.markText(CodeMirror.pos(fromLine, 0), from, intralineBgOpt);
|
||||
}
|
||||
cm.markText(from, to, diffOpt);
|
||||
last = to;
|
||||
@@ -511,14 +600,20 @@ public class CodeMirrorDemo extends Screen {
|
||||
LineClassWhere.BACKGROUND, diffTable.style.activeLineBg());
|
||||
}
|
||||
int line = cm.getCursor("head").getLine();
|
||||
LineHandle handle = cm.getLineHandle(line);
|
||||
// Ugly workaround because CodeMirror never hides lines completely.
|
||||
if (hiddenSkipMap.containsKey(handle)) {
|
||||
line -= hiddenSkipMap.get(handle);
|
||||
handle = cm.getLineHandle(line);
|
||||
}
|
||||
LineOnOtherInfo info =
|
||||
mapper.lineOnOther(cm == cmA ? Side.PARENT : Side.REVISION, line);
|
||||
int oLine = info.getLine();
|
||||
cm.setActiveLine(line);
|
||||
cm.setActiveLine(handle);
|
||||
cm.addLineClass(line, LineClassWhere.WRAP, diffTable.style.activeLine());
|
||||
cm.addLineClass(line, LineClassWhere.BACKGROUND, diffTable.style.activeLineBg());
|
||||
if (info.isAligned()) {
|
||||
other.setActiveLine(oLine);
|
||||
other.setActiveLine(other.getLineHandle(oLine));
|
||||
other.addLineClass(oLine, LineClassWhere.WRAP,
|
||||
diffTable.style.activeLine());
|
||||
other.addLineClass(oLine, LineClassWhere.BACKGROUND,
|
||||
@@ -531,8 +626,8 @@ public class CodeMirrorDemo extends Screen {
|
||||
private Runnable insertNewDraft(final CodeMirror cm) {
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
int line = cm.getActiveLine();
|
||||
LineHandle handle = cm.getLineHandle(line);
|
||||
LineHandle handle = cm.getActiveLine();
|
||||
int line = cm.getLineNumber(handle);
|
||||
CommentBox box = lineActiveBoxMap.get(handle);
|
||||
if (box == null) {
|
||||
lineActiveBoxMap.put(handle, addNewDraft(cm, line));
|
||||
|
@@ -0,0 +1,166 @@
|
||||
//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 com.google.gerrit.client.diff;
|
||||
|
||||
import com.google.gerrit.client.patches.PatchUtil;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.resources.client.CssResource;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.uibinder.client.UiHandler;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||
|
||||
import net.codemirror.lib.CodeMirror;
|
||||
import net.codemirror.lib.CodeMirror.LineHandle;
|
||||
import net.codemirror.lib.Configuration;
|
||||
import net.codemirror.lib.LineWidget;
|
||||
import net.codemirror.lib.TextMarker;
|
||||
import net.codemirror.lib.TextMarker.FromTo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/** The Widget that handles expanding of skipped lines */
|
||||
class SkipBar extends Composite {
|
||||
interface Binder extends UiBinder<HTMLPanel, SkipBar> {}
|
||||
private static Binder uiBinder = GWT.create(Binder.class);
|
||||
private static final int NUM_ROWS_TO_EXPAND = 10;
|
||||
private static final int UP_DOWN_THRESHOLD = 30;
|
||||
private static final Configuration COLLAPSED =
|
||||
Configuration.create().set("collapsed", true);
|
||||
|
||||
private LineWidget widget;
|
||||
|
||||
interface SkipBarStyle extends CssResource {
|
||||
String noExpand();
|
||||
}
|
||||
|
||||
@UiField(provided=true)
|
||||
Anchor skipNum;
|
||||
|
||||
@UiField(provided=true)
|
||||
Anchor upArrow;
|
||||
|
||||
@UiField(provided=true)
|
||||
Anchor downArrow;
|
||||
|
||||
@UiField
|
||||
SkipBarStyle style;
|
||||
|
||||
private TextMarker marker;
|
||||
private SkipBar otherBar;
|
||||
private CodeMirror cm;
|
||||
private int numSkipLines;
|
||||
private Map<LineHandle, Integer> hiddenSkipMap;
|
||||
|
||||
SkipBar(CodeMirror cm, Map<LineHandle, Integer> hiddenSkipMap) {
|
||||
this.cm = cm;
|
||||
this.hiddenSkipMap = hiddenSkipMap;
|
||||
skipNum = new Anchor(true);
|
||||
upArrow = new Anchor(true);
|
||||
downArrow = new Anchor(true);
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
}
|
||||
|
||||
void setWidget(LineWidget widget) {
|
||||
this.widget = widget;
|
||||
}
|
||||
|
||||
void setMarker(TextMarker marker, int length) {
|
||||
this.marker = marker;
|
||||
numSkipLines = length;
|
||||
skipNum.setText(Integer.toString(length));
|
||||
if (checkAndUpdateArrows()) {
|
||||
upArrow.setHTML(PatchUtil.M.expandBefore(NUM_ROWS_TO_EXPAND));
|
||||
downArrow.setHTML(PatchUtil.M.expandAfter(NUM_ROWS_TO_EXPAND));
|
||||
}
|
||||
}
|
||||
|
||||
static void link(SkipBar barA, SkipBar barB) {
|
||||
barA.otherBar = barB;
|
||||
barB.otherBar = barA;
|
||||
}
|
||||
|
||||
private void updateSkipNum() {
|
||||
numSkipLines -= NUM_ROWS_TO_EXPAND;
|
||||
skipNum.setText(String.valueOf(numSkipLines));
|
||||
checkAndUpdateArrows();
|
||||
}
|
||||
|
||||
private boolean checkAndUpdateArrows() {
|
||||
if (numSkipLines <= UP_DOWN_THRESHOLD) {
|
||||
upArrow.addStyleName(style.noExpand());
|
||||
downArrow.addStyleName(style.noExpand());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void expandAll() {
|
||||
hiddenSkipMap.remove(
|
||||
cm.getLineHandle(marker.find().getTo().getLine()));
|
||||
marker.clear();
|
||||
widget.clear();
|
||||
removeFromParent();
|
||||
}
|
||||
|
||||
private void expandBefore() {
|
||||
FromTo fromTo = marker.find();
|
||||
marker.clear();
|
||||
int oldStart = fromTo.getFrom().getLine();
|
||||
int newStart = oldStart + NUM_ROWS_TO_EXPAND;
|
||||
int end = fromTo.getTo().getLine();
|
||||
marker = cm.markText(CodeMirror.pos(newStart), CodeMirror.pos(end), COLLAPSED);
|
||||
Configuration config = Configuration.create().set("coverGutter", true);
|
||||
LineWidget newWidget = cm.addLineWidget(newStart, getElement(), config);
|
||||
widget.clear();
|
||||
setWidget(newWidget);
|
||||
updateSkipNum();
|
||||
hiddenSkipMap.put(cm.getLineHandle(end), numSkipLines);
|
||||
}
|
||||
|
||||
private void expandAfter() {
|
||||
FromTo fromTo = marker.find();
|
||||
marker.clear();
|
||||
int oldEnd = fromTo.getTo().getLine();
|
||||
int newEnd = oldEnd - NUM_ROWS_TO_EXPAND;
|
||||
marker = cm.markText(CodeMirror.pos(fromTo.getFrom().getLine()),
|
||||
CodeMirror.pos(newEnd),
|
||||
COLLAPSED);
|
||||
updateSkipNum();
|
||||
hiddenSkipMap.remove(cm.getLineHandle(oldEnd));
|
||||
hiddenSkipMap.put(cm.getLineHandle(newEnd), numSkipLines);
|
||||
}
|
||||
|
||||
@UiHandler("skipNum")
|
||||
void onExpandAll(ClickEvent e) {
|
||||
otherBar.expandAll();
|
||||
expandAll();
|
||||
}
|
||||
|
||||
@UiHandler("upArrow")
|
||||
void onExpandBefore(ClickEvent e) {
|
||||
otherBar.expandBefore();
|
||||
expandBefore();
|
||||
}
|
||||
|
||||
@UiHandler("downArrow")
|
||||
void onExpandAfter(ClickEvent e) {
|
||||
otherBar.expandAfter();
|
||||
expandAfter();
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
|
||||
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
|
||||
<ui:style type='com.google.gerrit.client.diff.SkipBar.SkipBarStyle'>
|
||||
.skipBar {
|
||||
background-color: #def;
|
||||
}
|
||||
.text {
|
||||
display: table;
|
||||
margin: 0 auto;
|
||||
color: #777;
|
||||
font-style: italic;
|
||||
overflow: hidden;
|
||||
}
|
||||
.anchor {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
.noExpand {
|
||||
display: none;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel styleName='{style.skipBar}'>
|
||||
<div class='{style.text}'>
|
||||
<ui:msg>
|
||||
<g:Anchor ui:field='upArrow' styleName='{style.anchor}'>
|
||||
</g:Anchor>
|
||||
<span>... skipped </span>
|
||||
<g:Anchor ui:field='skipNum' styleName='{style.anchor}'>
|
||||
</g:Anchor>
|
||||
<span> common lines ...</span>
|
||||
<g:Anchor ui:field='downArrow' styleName='{style.anchor}'>
|
||||
</g:Anchor>
|
||||
</ui:msg>
|
||||
</div>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
@@ -25,8 +25,4 @@ public interface Addons extends ClientBundle {
|
||||
@Source("selection/mark-selection.js")
|
||||
@DoNotEmbed
|
||||
DataResource mark_selection();
|
||||
|
||||
@Source("fold/foldcode.js")
|
||||
@DoNotEmbed
|
||||
DataResource foldcode();
|
||||
}
|
||||
|
@@ -47,9 +47,9 @@ public class CodeMirror extends JavaScriptObject {
|
||||
public final native void refresh() /*-{ this.refresh(); }-*/;
|
||||
public final native Element getWrapperElement() /*-{ return this.getWrapperElement(); }-*/;
|
||||
|
||||
public final native void markText(LineCharacter from, LineCharacter to,
|
||||
public final native TextMarker markText(LineCharacter from, LineCharacter to,
|
||||
Configuration options) /*-{
|
||||
this.markText(from, to, options);
|
||||
return this.markText(from, to, options);
|
||||
}-*/;
|
||||
|
||||
public enum LineClassWhere {
|
||||
@@ -66,6 +66,16 @@ public class CodeMirror extends JavaScriptObject {
|
||||
this.addLineClass(line, where, lineClass);
|
||||
}-*/;
|
||||
|
||||
public final void addLineClass(LineHandle line, LineClassWhere where,
|
||||
String className) {
|
||||
addLineClassNative(line, where.name().toLowerCase(), className);
|
||||
}
|
||||
|
||||
private final native void addLineClassNative(LineHandle line, String where,
|
||||
String lineClass) /*-{
|
||||
this.addLineClass(line, where, lineClass);
|
||||
}-*/;
|
||||
|
||||
public final void removeLineClass(int line, LineClassWhere where,
|
||||
String className) {
|
||||
removeLineClassNative(line, where.name().toLowerCase(), className);
|
||||
@@ -76,6 +86,17 @@ public class CodeMirror extends JavaScriptObject {
|
||||
this.removeLineClass(line, where, lineClass);
|
||||
}-*/;
|
||||
|
||||
public final void removeLineClass(LineHandle line, LineClassWhere where,
|
||||
String className) {
|
||||
removeLineClassNative(line, where.name().toLowerCase(), className);
|
||||
}
|
||||
|
||||
private final native void removeLineClassNative(LineHandle line, String where,
|
||||
String lineClass) /*-{
|
||||
this.removeLineClass(line, where, lineClass);
|
||||
}-*/;
|
||||
|
||||
|
||||
public final native void addWidget(LineCharacter pos, Element node,
|
||||
boolean scrollIntoView) /*-{
|
||||
this.addWidget(pos, node, scrollIntoView);
|
||||
@@ -120,20 +141,32 @@ public class CodeMirror extends JavaScriptObject {
|
||||
return this.state.hasOwnProperty('activeLine');
|
||||
}-*/;
|
||||
|
||||
public final native int getActiveLine() /*-{
|
||||
public final native LineHandle getActiveLine() /*-{
|
||||
return this.state.activeLine;
|
||||
}-*/;
|
||||
|
||||
public final native void setActiveLine(int line) /*-{
|
||||
public final native void setActiveLine(LineHandle line) /*-{
|
||||
this.state.activeLine = line;
|
||||
}-*/;
|
||||
|
||||
public final native void addKeyMap(KeyMap map) /*-{ this.addKeyMap(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 LineHandle getLineHandle(int line) /*-{
|
||||
return this.getLineHandle(line);
|
||||
}-*/;
|
||||
|
||||
public final native int getLineNumber(LineHandle handle) /*-{
|
||||
return this.getLineNumber(handle);
|
||||
}-*/;
|
||||
|
||||
protected CodeMirror() {
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package net.codemirror.lib;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
|
||||
/**
|
||||
* Simple map-like structure to pass configuration to CodeMirror.
|
||||
@@ -36,6 +37,9 @@ public class Configuration extends JavaScriptObject {
|
||||
public final native Configuration set(String name, boolean val)
|
||||
/*-{ this[name] = val; return this; }-*/;
|
||||
|
||||
public final native Configuration set(String name, JavaScriptObject val)
|
||||
/*-{ this[name] = val; return this; }-*/;
|
||||
|
||||
protected Configuration() {
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,14 @@ 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);
|
||||
|
@@ -44,8 +44,6 @@ 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.foldcode().getSafeUri(),
|
||||
group.addFinal(cb));
|
||||
}
|
||||
}
|
||||
|
39
gerrit-gwtui/src/main/java/net/codemirror/lib/TextMarker.java
vendored
Normal file
39
gerrit-gwtui/src/main/java/net/codemirror/lib/TextMarker.java
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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;
|
||||
|
||||
/** 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(); }-*/;
|
||||
|
||||
protected TextMarker() {
|
||||
}
|
||||
|
||||
public static class FromTo extends JavaScriptObject {
|
||||
public final native LineCharacter getFrom() /*-{ return this.from; }-*/;
|
||||
public final native LineCharacter getTo() /*-{ return this.to; }-*/;
|
||||
|
||||
protected FromTo() {
|
||||
}
|
||||
}
|
||||
}
|
@@ -48,7 +48,7 @@ public class EditIteratorTest extends GwtTest {
|
||||
@Test
|
||||
public void testNoAdvance() {
|
||||
EditIterator iter = new EditIterator(lines, 0);
|
||||
assertLineChsEqual(LineCharacter.create(0, 0), iter.advance(0));
|
||||
assertLineChsEqual(LineCharacter.create(0), iter.advance(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,7 +66,7 @@ public class EditIteratorTest extends GwtTest {
|
||||
@Test
|
||||
public void testEndsOnNewline() {
|
||||
EditIterator iter = new EditIterator(lines, 0);
|
||||
assertLineChsEqual(LineCharacter.create(1, 0), iter.advance(4));
|
||||
assertLineChsEqual(LineCharacter.create(1), iter.advance(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user