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