Search in sources :

Example 1 with Marker

use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Marker in project rstudio by rstudio.

the class DiagnosticsBackgroundPopup method start.

public void start() {
    isRunning_ = true;
    stopRequested_ = false;
    if (handler_ != null) {
        handler_.removeHandler();
        handler_ = null;
    }
    handler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(NativePreviewEvent event) {
            if (event.getTypeInt() == Event.ONMOUSEMOVE) {
                movedMouseMostRecently_ = true;
                Element target = Element.as(event.getNativeEvent().getEventTarget());
                if (target.hasClassName("ace_gutter-cell")) {
                    lastMouseCoords_ = null;
                    hidePopup();
                    return;
                }
                lastMouseCoords_ = ScreenCoordinates.create(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                if (activeMarker_ != null && !activeMarker_.getRange().containsRightExclusive(editor_.toDocumentPosition(lastMouseCoords_))) {
                    hidePopup();
                }
            } else {
                movedMouseMostRecently_ = false;
            }
        }
    });
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

        @Override
        public boolean execute() {
            if (stopRequested_)
                return stopExecution();
            // restarted later)
            if (!docDisplay_.isFocused())
                return stopExecution();
            long currentTime = System.currentTimeMillis();
            long lastModifiedTime = docDisplay_.getLastModifiedTime();
            long lastCursorChangedTime = docDisplay_.getLastCursorChangedTime();
            // cursor was moved recently, then bail
            if ((currentTime - lastModifiedTime) < 500)
                return completeExecution();
            if ((currentTime - lastCursorChangedTime) < 500)
                return completeExecution();
            Markers markers = editor_.getSession().getMarkers(true);
            Position currentPos;
            if (movedMouseMostRecently_) {
                if (lastMouseCoords_ == null)
                    return completeExecution();
                currentPos = editor_.toDocumentPosition(lastMouseCoords_);
            } else {
                currentPos = docDisplay_.getCursorPosition();
            }
            int[] keys = markers.getIds();
            for (int i = 0; i < keys.length; i++) {
                Marker marker = markers.get(keys[i]);
                if (marker.getRange().containsRightExclusive(currentPos)) {
                    displayMarkerDiagnostics(marker);
                    return completeExecution();
                }
            }
            return completeExecution();
        }
    }, 500);
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Element(com.google.gwt.dom.client.Element) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Markers(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Markers) Marker(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Marker)

Example 2 with Marker

use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Marker in project rstudio by rstudio.

the class AceEditorWidget method removeMarkersAtCursorPosition.

public void removeMarkersAtCursorPosition() {
    // Defer this so other event handling can update anchors etc.
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            Position cursor = editor_.getCursorPosition();
            JsArray<AceAnnotation> newAnnotations = JsArray.createArray().cast();
            for (int i = 0; i < annotations_.size(); i++) {
                AnchoredAceAnnotation annotation = annotations_.get(i);
                int markerId = annotation.getMarkerId();
                Marker marker = editor_.getSession().getMarker(markerId);
                // a previous action.
                if (marker == null)
                    continue;
                Range range = marker.getRange();
                if (!range.contains(cursor))
                    newAnnotations.push(annotation.asAceAnnotation());
                else
                    editor_.getSession().removeMarker(markerId);
            }
            editor_.getSession().setAnnotations(newAnnotations);
            editor_.getRenderer().renderMarkers();
        }
    });
}
Also used : JsArray(com.google.gwt.core.client.JsArray) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Marker(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Marker) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range) AnchoredRange(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AnchoredRange)

Example 3 with Marker

use of org.rstudio.studio.client.workbench.views.source.editors.text.ace.Marker in project rstudio by rstudio.

the class AceEditorWidget method removeMarkersOnCursorLine.

public void removeMarkersOnCursorLine() {
    // Defer this so other event handling can update anchors etc.
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            int cursorRow = editor_.getCursorPosition().getRow();
            JsArray<AceAnnotation> newAnnotations = JsArray.createArray().cast();
            for (int i = 0; i < annotations_.size(); i++) {
                AnchoredAceAnnotation annotation = annotations_.get(i);
                int markerId = annotation.getMarkerId();
                Marker marker = editor_.getSession().getMarker(markerId);
                // a previous action.
                if (marker == null)
                    continue;
                Range range = marker.getRange();
                int rowStart = range.getStart().getRow();
                int rowEnd = range.getEnd().getRow();
                if (cursorRow >= rowStart && cursorRow <= rowEnd)
                    editor_.getSession().removeMarker(markerId);
                else
                    newAnnotations.push(annotation.asAceAnnotation());
            }
            editor_.getSession().setAnnotations(newAnnotations);
            editor_.getRenderer().renderMarkers();
        }
    });
}
Also used : JsArray(com.google.gwt.core.client.JsArray) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Marker(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Marker) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range) AnchoredRange(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AnchoredRange)

Aggregations

Marker (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Marker)3 JsArray (com.google.gwt.core.client.JsArray)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 AnchoredRange (org.rstudio.studio.client.workbench.views.source.editors.text.ace.AnchoredRange)2 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)2 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)2 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 Element (com.google.gwt.dom.client.Element)1 NativePreviewEvent (com.google.gwt.user.client.Event.NativePreviewEvent)1 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)1 Markers (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Markers)1