Search in sources :

Example 1 with LinearRange

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

the class QuickAssistWidget method createItem.

public Element createItem(final CompletionProposal proposal) {
    final Element element = Elements.createLiElement(popupResources.popupStyle().item());
    final Element icon = Elements.createDivElement(popupResources.popupStyle().icon());
    if (proposal.getIcon() != null && proposal.getIcon().getSVGImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getSVGImage().getElement());
    } else if (proposal.getIcon() != null && proposal.getIcon().getImage() != null) {
        icon.appendChild((Node) proposal.getIcon().getImage().getElement());
    }
    element.appendChild(icon);
    final SpanElement label = Elements.createSpanElement(popupResources.popupStyle().label());
    label.setInnerHTML(proposal.getDisplayString());
    element.appendChild(label);
    final EventListener validateListener = new EventListener() {

        @Override
        public void handleEvent(final Event evt) {
            proposal.getCompletion(new CompletionProposal.CompletionCallback() {

                @Override
                public void onCompletion(final Completion completion) {
                    HandlesUndoRedo undoRedo = null;
                    if (textEditor instanceof UndoableEditor) {
                        UndoableEditor undoableEditor = (UndoableEditor) QuickAssistWidget.this.textEditor;
                        undoRedo = undoableEditor.getUndoRedo();
                    }
                    try {
                        if (undoRedo != null) {
                            undoRedo.beginCompoundChange();
                        }
                        completion.apply(textEditor.getDocument());
                        final LinearRange selection = completion.getSelection(textEditor.getDocument());
                        if (selection != null) {
                            textEditor.getDocument().setSelectedRange(selection, true);
                        }
                    } catch (final Exception e) {
                        Log.error(getClass(), e);
                    } finally {
                        if (undoRedo != null) {
                            undoRedo.endCompoundChange();
                        }
                    }
                }
            });
            hide();
        }
    };
    element.addEventListener(Event.DBLCLICK, validateListener, false);
    element.addEventListener(CUSTOM_EVT_TYPE_VALIDATE, validateListener, false);
    return element;
}
Also used : SpanElement(elemental.html.SpanElement) UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) CompletionProposal(org.eclipse.che.ide.api.editor.codeassist.CompletionProposal) Element(elemental.dom.Element) SpanElement(elemental.html.SpanElement) Node(elemental.dom.Node) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) Completion(org.eclipse.che.ide.api.editor.codeassist.Completion) Event(elemental.events.Event) CustomEvent(elemental.events.CustomEvent) EventListener(elemental.events.EventListener)

Example 2 with LinearRange

use of org.eclipse.che.ide.api.editor.text.LinearRange 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 3 with LinearRange

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

the class ContentAssistWidget method applyCompletion.

private void applyCompletion(Completion completion) {
    textEditor.setFocus();
    UndoableEditor undoableEditor = textEditor;
    HandlesUndoRedo undoRedo = undoableEditor.getUndoRedo();
    try {
        if (undoRedo != null) {
            undoRedo.beginCompoundChange();
        }
        completion.apply(textEditor.getDocument());
        final LinearRange selection = completion.getSelection(textEditor.getDocument());
        if (selection != null) {
            textEditor.getDocument().setSelectedRange(selection, true);
        }
    } catch (final Exception e) {
        Log.error(getClass(), e);
    } finally {
        if (undoRedo != null) {
            undoRedo.endCompoundChange();
        }
    }
}
Also used : UndoableEditor(org.eclipse.che.ide.api.editor.texteditor.UndoableEditor) HandlesUndoRedo(org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo) LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange)

Example 4 with LinearRange

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

the class OrionDocument method setSelectedRange.

@Override
public void setSelectedRange(TextRange range, boolean show) {
    int lineStart = getLineStart(range.getFrom().getLine());
    int lineEnd = getLineStart(range.getTo().getLine());
    LinearRange linearRange = LinearRange.createWithStart(lineStart + range.getFrom().getCharacter()).andEnd(lineEnd + range.getTo().getCharacter());
    setSelectedRange(linearRange, show);
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange)

Example 5 with LinearRange

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

the class MinimapAnnotationRenderer method removeAnnotationItem.

private void removeAnnotationItem(final AnnotationModelEvent event, final Annotation annotation, final Map<Integer, List<Annotation>> toRestore) {
    final Position position = event.getPositionOfRemovedAnnotation(annotation);
    final TextPosition textPosition = this.document.getPositionFromIndex(position.getOffset());
    final int line = textPosition.getLine();
    // remove all marks on the line
    this.minimap.removeMarks(line, line);
    // restore marks that are not removed
    final LinearRange rangeForLine = this.document.getLinearRangeForLine(line);
    final AnnotationModel model = event.getAnnotationModel();
    final Iterator<Annotation> it = model.getAnnotationIterator(rangeForLine.getStartOffset(), rangeForLine.getLength(), false, true);
    while (it.hasNext()) {
        final Annotation current = it.next();
        List<Annotation> lineAnnotations = toRestore.get(line);
        if (!current.equals(annotation)) {
            if (lineAnnotations == null) {
                lineAnnotations = new ArrayList<>();
                toRestore.put(line, lineAnnotations);
            }
            lineAnnotations.add(current);
        } else {
            if (lineAnnotations != null) {
                lineAnnotations.removeAll(Collections.singletonList(current));
                if (lineAnnotations.isEmpty()) {
                    toRestore.remove(line);
                }
            }
        }
    }
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) 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) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation)

Aggregations

LinearRange (org.eclipse.che.ide.api.editor.text.LinearRange)8 Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)4 Position (org.eclipse.che.ide.api.editor.text.Position)3 ArrayList (java.util.ArrayList)2 TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)2 HandlesUndoRedo (org.eclipse.che.ide.api.editor.texteditor.HandlesUndoRedo)2 UndoableEditor (org.eclipse.che.ide.api.editor.texteditor.UndoableEditor)2 Element (elemental.dom.Element)1 Node (elemental.dom.Node)1 CustomEvent (elemental.events.CustomEvent)1 Event (elemental.events.Event)1 EventListener (elemental.events.EventListener)1 SpanElement (elemental.html.SpanElement)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 QueryAnnotationsEvent (org.eclipse.che.ide.api.editor.annotation.QueryAnnotationsEvent)1 Completion (org.eclipse.che.ide.api.editor.codeassist.Completion)1 CompletionProposal (org.eclipse.che.ide.api.editor.codeassist.CompletionProposal)1 Document (org.eclipse.che.ide.api.editor.document.Document)1