Search in sources :

Example 6 with TextPosition

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

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

Example 8 with TextPosition

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);
}
Also used : 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) Element(elemental.dom.Element)

Example 9 with TextPosition

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);
}
Also used : DocumentHandle(org.eclipse.che.ide.api.editor.document.DocumentHandle) 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) Document(org.eclipse.che.ide.api.editor.document.Document) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)

Example 10 with TextPosition

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);
}
Also used : VersionedTextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO) TextDocumentContentChangeEventDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO) DidChangeTextDocumentParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document) RangeDTO(org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO) PositionDTO(org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)

Aggregations

TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)34 Position (org.eclipse.che.ide.api.editor.text.Position)9 TextChange (org.eclipse.che.ide.api.editor.changeintercept.TextChange)8 TextRange (org.eclipse.che.ide.api.editor.text.TextRange)7 Test (org.junit.Test)7 Document (org.eclipse.che.ide.api.editor.document.Document)6 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)5 Ignore (org.junit.Ignore)4 Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)3 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)3 Element (elemental.dom.Element)2 ArrayList (java.util.ArrayList)2 PositionDTO (org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)2 SymbolInformationDTO (org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO)2 DocumentHandle (org.eclipse.che.ide.api.editor.document.DocumentHandle)2 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)2 File (org.eclipse.che.ide.api.resources.File)2 Match (org.eclipse.che.plugin.languageserver.ide.filters.Match)2 Optional (com.google.common.base.Optional)1 Timer (com.google.gwt.user.client.Timer)1