use of org.eclipse.che.ide.api.editor.text.TextPosition 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.TextPosition 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);
}
use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.
the class GutterAnnotationRenderer method removeAnnotationItem.
private void removeAnnotationItem(final AnnotationModelEvent event, final Annotation annotation) {
final Position position = event.getPositionOfRemovedAnnotation(annotation);
final TextPosition textPosition = this.document.getPositionFromIndex(position.getOffset());
final Element annotationItem = this.hasGutter.getGutterItem(textPosition.getLine(), ANNOTATION_GUTTER);
if (AnnotationGroupImpl.isAnnotation(annotationItem)) {
final AnnotationGroup group = AnnotationGroupImpl.create(annotationItem);
group.removeAnnotation(annotation, position.getOffset());
if (group.getAnnotationCount() != 0) {
return;
}
}
// else
this.hasGutter.removeGutterItem(textPosition.getLine(), ANNOTATION_GUTTER);
}
use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.
the class LanguageServerAnnotationModel method createPositionFromDiagnostic.
protected Position createPositionFromDiagnostic(final DiagnosticDTO diagnostic) {
DocumentHandle documentHandle = getDocumentHandle();
Document document = documentHandle.getDocument();
RangeDTO range = diagnostic.getRange();
int start = document.getIndexFromPosition(new TextPosition(range.getStart().getLine(), range.getStart().getCharacter()));
int end = document.getIndexFromPosition(new TextPosition(range.getEnd().getLine(), range.getEnd().getCharacter()));
if (start == -1 && end == -1) {
return new Position(0);
}
if (start == -1) {
return new Position(end);
}
if (end == -1) {
return new Position(start);
}
int length = end - start;
if (length < 0) {
return null;
}
return new Position(start, length);
}
use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.
the class IncrementalTextDocumentSynchronize method syncTextDocument.
@Override
public void syncTextDocument(DocumentChangeEvent event, int version) {
Document document = event.getDocument().getDocument();
TextPosition startPosition = document.getPositionFromIndex(event.getOffset());
TextPosition endPosition;
if (event.getRemoveCharCount() != 0) {
endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter() + event.getRemoveCharCount());
} else {
endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter());
}
DidChangeTextDocumentParamsDTO changeDTO = dtoFactory.createDto(DidChangeTextDocumentParamsDTO.class);
String uri = document.getFile().getLocation().toString();
changeDTO.setUri(uri);
VersionedTextDocumentIdentifierDTO versionedDocId = dtoFactory.createDto(VersionedTextDocumentIdentifierDTO.class);
versionedDocId.setUri(uri);
versionedDocId.setVersion(version);
changeDTO.setTextDocument(versionedDocId);
RangeDTO range = dtoFactory.createDto(RangeDTO.class);
PositionDTO start = dtoFactory.createDto(PositionDTO.class);
start.setLine(startPosition.getLine());
start.setCharacter(startPosition.getCharacter());
PositionDTO end = dtoFactory.createDto(PositionDTO.class);
end.setLine(endPosition.getLine());
end.setCharacter(endPosition.getCharacter());
range.setStart(start);
range.setEnd(end);
TextDocumentContentChangeEventDTO actualChange = dtoFactory.createDto(TextDocumentContentChangeEventDTO.class);
actualChange.setRange(range);
actualChange.setText(event.getText());
changeDTO.setContentChanges(Collections.singletonList(actualChange));
textDocumentService.didChange(changeDTO);
}
Aggregations