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);
}
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();
}
});
}
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();
}
});
}
Aggregations