Search in sources :

Example 1 with CodeMirror

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);
}
Also used : ChangesHandler(net.codemirror.lib.CodeMirror.ChangesHandler) ResizeHandler(com.google.gwt.event.logical.shared.ResizeHandler) ClosingEvent(com.google.gwt.user.client.Window.ClosingEvent) ClosingHandler(com.google.gwt.user.client.Window.ClosingHandler) CodeMirror(net.codemirror.lib.CodeMirror) ResizeEvent(com.google.gwt.event.logical.shared.ResizeEvent)

Example 2 with CodeMirror

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();
                    }
                });
            }
        });
    };
}
Also used : LineHandle(net.codemirror.lib.CodeMirror.LineHandle) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) LineOnOtherInfo(com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo) CodeMirror(net.codemirror.lib.CodeMirror)

Example 3 with CodeMirror

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

Example 4 with CodeMirror

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);
            }
        }
    }
}
Also used : SkippedLine(com.google.gerrit.client.patches.SkippedLine) CodeMirror(net.codemirror.lib.CodeMirror)

Example 5 with CodeMirror

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);
}
Also used : CallbackGroup(com.google.gerrit.client.rpc.CallbackGroup) 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