Search in sources :

Example 11 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class DefaultPartitioner method getFirstIndexStartingAfterOffset.

/**
     * Returns the index of the first position which starts at or after the given offset.
     *
     * @param positions the positions in linear order
     * @param offset the offset
     * @return the index of the first position which starts after the offset
     */
private static int getFirstIndexStartingAfterOffset(List<TypedPosition> positions, int offset) {
    int i = -1;
    int j = positions.size();
    while (j - i > 1) {
        final int k = (i + j) >> 1;
        final Position p = positions.get(k);
        if (p.getOffset() >= offset) {
            j = k;
        } else {
            i = k;
        }
    }
    return j;
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition)

Example 12 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class AnnotationModelImpl method onQueryAnnotations.

@Override
public void onQueryAnnotations(final QueryAnnotationsEvent event) {
    final QueryAnnotationsEvent.QueryCallback callback = event.getCallback();
    if (callback == null) {
        return;
    }
    final LinearRange range = event.getRange();
    Iterator<Annotation> iterator;
    if (range == null) {
        iterator = getAnnotationIterator();
    } else {
        iterator = getAnnotationIterator(range.getStartOffset(), range.getLength(), true, true);
    }
    final QueryAnnotationsEvent.AnnotationFilter filter = event.getAdditionalFilter();
    final Map<Annotation, Position> result = new HashMap<>();
    while (iterator.hasNext()) {
        final Annotation annotation = iterator.next();
        if (filter.accept(annotation)) {
            result.put(annotation, this.annotations.get(annotation));
        }
    }
    callback.respond(result);
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 13 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class AnnotationModelImpl method cleanup.

/**
     * Removes all annotations from the model whose associated positions have been deleted. If requested inform all model listeners about
     * the change. If requested a new thread is created for the notification of the model listeners.
     *
     * @param fireModelChanged indicates whether to notify all model listeners
     */
private void cleanup(final boolean fireModelChanged) {
    if (documentChanged) {
        documentChanged = false;
        final List<Annotation> deleted = new ArrayList<Annotation>();
        final Iterator<Annotation> e = getAnnotationIterator();
        while (e.hasNext()) {
            final Annotation annotation = e.next();
            final Position pos = annotations.get(annotation);
            if (pos == null || pos.isDeleted()) {
                deleted.add(annotation);
            }
        }
        if (fireModelChanged) {
            removeAnnotations(deleted, false);
            if (modelEvent != null) {
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        fireModelChanged();
                    }
                });
            }
        } else {
            removeAnnotations(deleted, fireModelChanged);
        }
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) ArrayList(java.util.ArrayList) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 14 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class AnnotationModelImpl method forgetLines.

// TODO evaluate: keep?
private void forgetLines(final int fromLine, final int count, final boolean checkCount) {
    // use an iterator to have remove()
    final Iterator<Entry<Annotation, Position>> iterator = this.annotations.entrySet().iterator();
    while (iterator.hasNext()) {
        final Entry<Annotation, Position> entry = iterator.next();
        final Position position = entry.getValue();
        final TextPosition textPos = docHandle.getDocument().getPositionFromIndex(position.getOffset());
        final int line = textPos.getLine();
        if (line >= fromLine && (!checkCount || line < fromLine + count)) {
            iterator.remove();
        }
    }
}
Also used : Entry(java.util.Map.Entry) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Example 15 with Position

use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.

the class AnnotationModelImpl method shiftLines.

// TODO evaluate: keep?
public void shiftLines(final int fromLine, final int lineDelta, final int charDelta) {
    final Map<Annotation, Position> modified = new IdentityHashMap<>();
    for (final Entry<Annotation, Position> entry : this.annotations.entrySet()) {
        final Position position = entry.getValue();
        final TextPosition textPos = docHandle.getDocument().getPositionFromIndex(position.getOffset());
        int horizontal;
        if (textPos.getLine() == fromLine) {
            horizontal = charDelta;
        } else if (textPos.getLine() >= fromLine) {
            horizontal = 0;
        } else {
            continue;
        }
        final TextPosition newTextPos = new TextPosition(fromLine + lineDelta, textPos.getCharacter() + horizontal);
        final int newOffset = docHandle.getDocument().getIndexFromPosition(newTextPos);
        final Position newPos = new Position(newOffset, position.getLength());
        modified.put(entry.getKey(), newPos);
    }
    // merge changes in the annotartion map
    this.annotations.putAll(modified);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Position(org.eclipse.che.ide.api.editor.text.Position) TypedPosition(org.eclipse.che.ide.api.editor.text.TypedPosition) IdentityHashMap(java.util.IdentityHashMap) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Aggregations

Position (org.eclipse.che.ide.api.editor.text.Position)36 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)14 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)14 Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)8 BadPositionCategoryException (org.eclipse.che.ide.api.editor.text.BadPositionCategoryException)7 ArrayList (java.util.ArrayList)6 LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)3 Element (elemental.dom.Element)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 BadLocationException (org.eclipse.che.ide.api.editor.text.BadLocationException)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 DiagnosticDTO (org.eclipse.che.api.languageserver.shared.lsapi.DiagnosticDTO)1 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)1 EditorWithAutoSave (org.eclipse.che.ide.api.editor.EditorWithAutoSave)1 AnnotationModel (org.eclipse.che.ide.api.editor.annotation.AnnotationModel)1