use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.
the class OrionDocument method setSelectedRange.
/** {@inheritDoc} */
@Override
public void setSelectedRange(LinearRange range, boolean show) {
int startOffset = range.getStartOffset();
editorOverlay.setSelection(startOffset, startOffset + range.getLength(), show);
TextPosition position = getPositionFromIndex(startOffset);
if (show && position != null) {
int lineNumber = position.getLine();
int topIndex = lineNumber - MARGIN_TOP;
editorOverlay.getTextView().setTopIndex(topIndex > 0 ? topIndex : 0);
}
}
use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.
the class OrionDocument method getTextRangeForLine.
@Override
public TextRange getTextRangeForLine(final int line) {
final int startOffset = this.textViewOverlay.getModel().getLineStart(line);
final int endOffset = this.textViewOverlay.getModel().getLineEnd(line);
final int length = endOffset - startOffset;
return new TextRange(new TextPosition(line, 0), new TextPosition(line, length));
}
use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.
the class GutterAnnotationRenderer method addAnnotationItem.
private void addAnnotationItem(final AnnotationModel model, final Annotation annotation) {
final Position position = model.getPosition(annotation);
if (position == null) {
Log.warn(GutterAnnotationRenderer.class, "No position for annotation " + annotation);
return;
}
final TextPosition textPosition = this.document.getPositionFromIndex(position.getOffset());
final Element annotationItem = this.hasGutter.getGutterItem(textPosition.getLine(), ANNOTATION_GUTTER);
AnnotationGroup annotationGroup;
if (!AnnotationGroupImpl.isAnnotation(annotationItem)) {
LOG.fine("Create new annotation group for line " + textPosition.getLine());
final AnnotationGroup newGroup = AnnotationGroupImpl.create();
newGroup.getElement().addEventListener(Event.MOUSEOVER, new EventListener() {
@Override
public void handleEvent(final Event evt) {
showToolTip(newGroup, textPosition.getLine());
}
}, false);
this.hasGutter.addGutterItem(textPosition.getLine(), ANNOTATION_GUTTER, newGroup.getElement());
annotationGroup = newGroup;
} else {
LOG.fine("Reuse annotation group for line " + textPosition.getLine());
annotationGroup = AnnotationGroupImpl.create(annotationItem);
}
annotationGroup.addAnnotation(annotation, position.getOffset());
}
use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.
the class InlineAnnotationRenderer method addAnnotationItem.
/**
* Add an inline annotation.
*
* @param annotationModel the annotation model
* @param annotation the annotation to add
* @param decorations the available decorations
*/
private void addAnnotationItem(AnnotationModel annotationModel, Annotation annotation, Map<String, String> decorations) {
if (this.hasTextMarkers != null) {
final String className = decorations.get(annotation.getType());
if (className == null) {
return;
}
final Position position = annotationModel.getPosition(annotation);
if (position == null) {
Log.warn(InlineAnnotationRenderer.class, "Can't add annotation with no position");
return;
}
final TextPosition from = this.document.getPositionFromIndex(position.getOffset());
final TextPosition to = this.document.getPositionFromIndex(position.getOffset() + position.getLength());
final MarkerRegistration registration = this.hasTextMarkers.addMarker(new TextRange(from, to), className);
if (registration != null) {
this.markers.put(annotation, registration);
}
}
}
use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.
the class MinimapAnnotationRenderer method addAnnotationItem.
private void addAnnotationItem(final AnnotationModel model, final Annotation annotation, final Map<String, String> decorations) {
final Position position = model.getPosition(annotation);
if (position == null) {
Log.warn(MinimapAnnotationRenderer.class, "No position for annotation " + annotation);
return;
}
// final TextPosition textPosition = this.document.getPositionFromIndex(position.getOffset());
// final int line = textPosition.getLine();
final String style = decorations.get(annotation.getType());
this.minimap.addMark(position.getOffset(), style, annotation.getLayer(), annotation.getText());
}
Aggregations