Search in sources :

Example 21 with TextPosition

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);
    }
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition)

Example 22 with TextPosition

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));
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextRange(org.eclipse.che.ide.api.editor.text.TextRange)

Example 23 with TextPosition

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());
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Element(elemental.dom.Element) Event(elemental.events.Event) EventListener(elemental.events.EventListener)

Example 24 with TextPosition

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);
        }
    }
}
Also used : MarkerRegistration(org.eclipse.che.ide.api.editor.texteditor.HasTextMarkers.MarkerRegistration) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextRange(org.eclipse.che.ide.api.editor.text.TextRange)

Example 25 with TextPosition

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());
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position)

Aggregations

TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)34 Position (org.eclipse.che.ide.api.editor.text.Position)9 TextChange (org.eclipse.che.ide.api.editor.changeintercept.TextChange)8 TextRange (org.eclipse.che.ide.api.editor.text.TextRange)7 Test (org.junit.Test)7 Document (org.eclipse.che.ide.api.editor.document.Document)6 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)5 Ignore (org.junit.Ignore)4 Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)3 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)3 Element (elemental.dom.Element)2 ArrayList (java.util.ArrayList)2 PositionDTO (org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)2 SymbolInformationDTO (org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO)2 DocumentHandle (org.eclipse.che.ide.api.editor.document.DocumentHandle)2 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)2 File (org.eclipse.che.ide.api.resources.File)2 Match (org.eclipse.che.plugin.languageserver.ide.filters.Match)2 Optional (com.google.common.base.Optional)1 Timer (com.google.gwt.user.client.Timer)1