use of net.codemirror.lib.CodeMirror in project gerrit by GerritCodeReview.
the class EditScreen method onShowView.
@Override
public void onShowView() {
super.onShowView();
Window.enableScrolling(false);
JumpKeys.enable(false);
if (prefs.hideTopMenu()) {
Gerrit.setHeaderVisible(false);
}
resizeHandler = Window.addResizeHandler(new ResizeHandler() {
@Override
public void onResize(ResizeEvent event) {
adjustHeight();
}
});
closeHandler = Window.addWindowClosingHandler(new ClosingHandler() {
@Override
public void onWindowClosing(ClosingEvent event) {
if (!cmEdit.isClean(generation)) {
event.setMessage(EditConstants.I.closeUnsavedChanges());
}
}
});
generation = cmEdit.changeGeneration(true);
setClean(true);
cmEdit.on(new ChangesHandler() {
@Override
public void handle(CodeMirror cm) {
setClean(cm.isClean(generation));
}
});
adjustHeight();
cmEdit.on("cursorActivity", updateCursorPosition());
setShowTabs(prefs.showTabs());
setLineLength(prefs.lineLength());
cmEdit.refresh();
cmEdit.focus();
if (startLine > 0) {
cmEdit.scrollToLine(startLine);
}
updateActiveLine();
editPrefsAction = new EditPreferencesAction(this, prefs);
}
use of net.codemirror.lib.CodeMirror in project gerrit by GerritCodeReview.
the class SideBySide method updateActiveLine.
@Override
Runnable updateActiveLine(CodeMirror cm) {
CodeMirror other = otherCm(cm);
return () -> {
// The rendering of active lines has to be deferred. Reflow
// caused by adding and removing styles chokes Firefox when arrow
// key (or j/k) is held down. Performance on Chrome is fine
// without the deferral.
//
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
operation(() -> {
LineHandle handle = cm.getLineHandleVisualStart(cm.getCursor("end").line());
if (!cm.extras().activeLine(handle)) {
return;
}
LineOnOtherInfo info = lineOnOther(cm.side(), cm.getLineNumber(handle));
if (info.isAligned()) {
other.extras().activeLine(other.getLineHandle(info.getLine()));
} else {
other.extras().clearActiveLine();
}
});
}
});
};
}
use of net.codemirror.lib.CodeMirror in project gerrit by GerritCodeReview.
the class SideBySide method onShowView.
@Override
public void onShowView() {
super.onShowView();
operation(() -> {
resizeCodeMirror();
chunkManager.adjustPadding();
cmA.refresh();
cmB.refresh();
});
setLineLength(Patch.COMMIT_MSG.equals(path) ? 72 : prefs.lineLength());
diffTable.refresh();
if (getStartLine() == 0) {
DiffChunkInfo d = chunkManager.getFirst();
if (d != null) {
if (d.isEdit() && d.getSide() == DisplaySide.A) {
setStartSide(DisplaySide.B);
setStartLine(lineOnOther(d.getSide(), d.getStart()).getLine() + 1);
} else {
setStartSide(d.getSide());
setStartLine(d.getStart() + 1);
}
}
}
if (getStartSide() != null && getStartLine() > 0) {
CodeMirror cm = getCmFromSide(getStartSide());
cm.scrollToLine(getStartLine() - 1);
cm.focus();
} else {
cmA.setCursor(Pos.create(0));
cmA.focus();
}
if (Gerrit.isSignedIn() && prefs.autoReview()) {
header.autoReview();
}
prefetchNextFile();
}
use of net.codemirror.lib.CodeMirror in project gerrit by GerritCodeReview.
the class SkipManager method renderSkips.
private void renderSkips(List<SkippedLine> skips, int lineA, int lineB) {
if (!skips.isEmpty()) {
boolean isSideBySide = host.isSideBySide();
CodeMirror cmA = null;
if (isSideBySide) {
cmA = host.getCmFromSide(DisplaySide.A);
}
CodeMirror cmB = host.getCmFromSide(DisplaySide.B);
for (SkippedLine skip : skips) {
SkipBar barA = null;
SkipBar barB = newSkipBar(cmB, DisplaySide.B, skip);
skipBars.add(barB);
if (isSideBySide) {
barA = newSkipBar(cmA, DisplaySide.A, skip);
SkipBar.link(barA, barB);
skipBars.add(barA);
}
if (skip.getStartA() == 0 || skip.getStartB() == 0) {
if (isSideBySide) {
barA.upArrow.setVisible(false);
}
barB.upArrow.setVisible(false);
setLine0(barB);
} else if (skip.getStartA() + skip.getSize() == lineA || skip.getStartB() + skip.getSize() == lineB) {
if (isSideBySide) {
barA.downArrow.setVisible(false);
}
barB.downArrow.setVisible(false);
}
}
}
}
use of net.codemirror.lib.CodeMirror in project gerrit by GerritCodeReview.
the class DiffScreen method onUnload.
@Override
protected void onUnload() {
super.onUnload();
removeKeyHandlerRegistrations();
if (getCommentManager() != null) {
CallbackGroup group = new CallbackGroup();
getCommentManager().saveAllDrafts(group);
group.done();
}
if (resizeHandler != null) {
resizeHandler.removeHandler();
resizeHandler = null;
}
for (CodeMirror cm : getCms()) {
if (cm != null) {
cm.getWrapperElement().removeFromParent();
}
}
if (prefsAction != null) {
prefsAction.hide();
}
Window.enableScrolling(true);
Gerrit.setHeaderVisible(true);
}
Aggregations