Search in sources :

Example 6 with CodeMirror

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);
    }
}
Also used : CodeMirror(net.codemirror.lib.CodeMirror)

Example 7 with CodeMirror

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);
    }
}
Also used : CodeMirror(net.codemirror.lib.CodeMirror)

Example 8 with CodeMirror

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());
}
Also used : CodeMirror(net.codemirror.lib.CodeMirror)

Example 9 with CodeMirror

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();
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) CommentInfo(com.google.gerrit.client.changes.CommentInfo) LocalComments(com.google.gerrit.client.change.LocalComments) CodeMirror(net.codemirror.lib.CodeMirror)

Example 10 with CodeMirror

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();
        }
    });
}
Also used : ModeInfo(net.codemirror.mode.ModeInfo) NativeString(com.google.gerrit.client.rpc.NativeString) CommandRunner(net.codemirror.lib.CodeMirror.CommandRunner) CodeMirror(net.codemirror.lib.CodeMirror)

Aggregations

CodeMirror (net.codemirror.lib.CodeMirror)12 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 LocalComments (com.google.gerrit.client.change.LocalComments)1 CommentInfo (com.google.gerrit.client.changes.CommentInfo)1 LineOnOtherInfo (com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo)1 SkippedLine (com.google.gerrit.client.patches.SkippedLine)1 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)1 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)1 NativeString (com.google.gerrit.client.rpc.NativeString)1 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 ResizeEvent (com.google.gwt.event.logical.shared.ResizeEvent)1 ResizeHandler (com.google.gwt.event.logical.shared.ResizeHandler)1 ClosingEvent (com.google.gwt.user.client.Window.ClosingEvent)1 ClosingHandler (com.google.gwt.user.client.Window.ClosingHandler)1 ChangesHandler (net.codemirror.lib.CodeMirror.ChangesHandler)1 CommandRunner (net.codemirror.lib.CodeMirror.CommandRunner)1 GutterClickHandler (net.codemirror.lib.CodeMirror.GutterClickHandler)1 LineHandle (net.codemirror.lib.CodeMirror.LineHandle)1 ModeInfo (net.codemirror.mode.ModeInfo)1