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