use of net.codemirror.lib.CodeMirror in project gerrit by GerritCodeReview.
the class DiffScreen method updateRenderEntireFile.
void updateRenderEntireFile() {
boolean entireFile = renderEntireFile();
for (CodeMirror cm : getCms()) {
cm.removeKeyMap(RENDER_ENTIRE_FILE_KEYMAP);
if (entireFile) {
cm.addKeyMap(RENDER_ENTIRE_FILE_KEYMAP);
}
cm.setOption("viewportMargin", entireFile ? POSITIVE_INFINITY : 10);
}
}
use of net.codemirror.lib.CodeMirror in project gerrit by GerritCodeReview.
the class DiffTable method refresh.
void refresh() {
if (header) {
CodeMirror cm = getDiffScreen().getCmFromSide(DisplaySide.A);
diffHeaderText.getStyle().setMarginLeft(cm.getGutterElement().getOffsetWidth(), Unit.PX);
}
}
use of net.codemirror.lib.CodeMirror in project gerrit by GerritCodeReview.
the class ChunkManager method diffChunkNavHelper.
void diffChunkNavHelper(List<? extends DiffChunkInfo> chunks, DiffScreen host, int res, Direction dir) {
if (res < 0) {
res = -res - (dir == Direction.PREV ? 1 : 2);
}
res = res + (dir == Direction.PREV ? -1 : 1);
if (res < 0 || chunks.size() <= res) {
return;
}
DiffChunkInfo lookUp = chunks.get(res);
// If edit, skip the deletion chunk and set focus on the insertion one.
if (lookUp.isEdit() && lookUp.getSide() == A) {
res = res + (dir == Direction.PREV ? -1 : 1);
if (res < 0 || chunks.size() <= res) {
return;
}
}
DiffChunkInfo target = chunks.get(res);
CodeMirror targetCm = host.getCmFromSide(target.getSide());
int cmLine = getCmLine(target.getStart(), target.getSide());
targetCm.setCursor(Pos.create(cmLine));
targetCm.focus();
targetCm.scrollToY(targetCm.heightAtLine(cmLine, "local") - 0.5 * targetCm.scrollbarV().getClientHeight());
}
use of net.codemirror.lib.CodeMirror in project gerrit by GerritCodeReview.
the class DraftBox method save.
void save(CallbackGroup group) {
if (pendingGroup != null) {
pendingGroup.addListener(group);
return;
}
String message = editArea.getValue().trim();
if (message.length() == 0) {
return;
}
CommentInfo input = CommentInfo.copy(comment);
input.message(message);
enableEdit(false);
pendingGroup = group;
final LocalComments lc = new LocalComments(psId);
GerritCallback<CommentInfo> cb = new GerritCallback<CommentInfo>() {
@Override
public void onSuccess(CommentInfo result) {
enableEdit(true);
pendingGroup = null;
set(result);
setEdit(false);
if (autoClosed) {
setOpen(false);
}
getCommentManager().setUnsaved(DraftBox.this, false);
}
@Override
public void onFailure(Throwable e) {
enableEdit(true);
pendingGroup = null;
if (RestApi.isNotSignedIn(e)) {
CommentInfo saved = CommentInfo.copy(comment);
saved.message(editArea.getValue().trim());
lc.setInlineComment(saved);
}
super.onFailure(e);
}
};
if (input.id() == null) {
CommentApi.createDraft(psId, input, group.add(cb));
} else {
CommentApi.updateDraft(psId, input.id(), input, group.add(cb));
}
CodeMirror cm = getCm();
cm.vim().handleKey("<Esc>");
cm.focus();
}
use of net.codemirror.lib.CodeMirror in project gerrit by GerritCodeReview.
the class EditScreen method initEditor.
private void initEditor() {
ModeInfo mode = null;
String editContent = "";
if (content != null && content.getResult() != null) {
editContent = content.getResult().asString();
if (prefs.syntaxHighlighting()) {
mode = ModeInfo.findMode(content.getContentType(), path);
}
}
mv = MergeView.create(editor, Configuration.create().set("autoCloseBrackets", prefs.autoCloseBrackets()).set("cursorBlinkRate", prefs.cursorBlinkRate()).set("cursorHeight", 0.85).set("indentUnit", prefs.indentUnit()).set("keyMap", prefs.keyMapType().name().toLowerCase()).set("lineNumbers", prefs.hideLineNumbers()).set("lineWrapping", false).set("matchBrackets", prefs.matchBrackets()).set("mode", mode != null ? mode.mime() : null).set("origLeft", editContent).set("scrollbarStyle", "overlay").set("showTrailingSpace", prefs.showWhitespaceErrors()).set("styleSelectedText", true).set("tabSize", prefs.tabSize()).set("theme", prefs.theme().name().toLowerCase()).set("value", ""));
cmBase = mv.leftOriginal();
cmBase.getWrapperElement().addClassName(style.base());
cmEdit = mv.editor();
setCmBaseValue();
cmEdit.setValue(editContent);
CodeMirror.addCommand("save", new CommandRunner() {
@Override
public void run(CodeMirror instance) {
save().run();
}
});
}
Aggregations