Search in sources :

Example 26 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition 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)

Example 27 with TextPosition

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

the class CloseCStyleCommentChangeInterceptorTest method testCloseComment.

@Test
public void testCloseComment() {
    doReturn("/**").when(document).getLineContent(0);
    doReturn(" *").when(document).getLineContent(1);
    final TextChange input = new TextChange.Builder().from(new TextPosition(0, 0)).to(new TextPosition(1, 2)).insert("/**\n *").build();
    final TextChange output = interceptor.processChange(input, document);
    assertNull(output);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextChange(org.eclipse.che.ide.api.editor.changeintercept.TextChange) Test(org.junit.Test)

Example 28 with TextPosition

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

the class CloseCStyleCommentChangeInterceptorTest method testJavadocStyleComment.

@Ignore
@Test
public void testJavadocStyleComment() {
    doReturn("/**").when(document).getLineContent(0);
    doReturn(" *").when(document).getLineContent(1);
    final TextChange input = new TextChange.Builder().from(new TextPosition(0, 3)).to(new TextPosition(1, 2)).insert("\n *").build();
    final TextChange output = interceptor.processChange(input, document);
    assertNotNull(output);
    final TextChange expected = new TextChange.Builder().from(new TextPosition(0, 3)).to(new TextPosition(2, 3)).insert("\n * \n */").build();
    Assert.assertEquals(expected, output);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextChange(org.eclipse.che.ide.api.editor.changeintercept.TextChange) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 29 with TextPosition

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

the class CloseCStyleCommentChangeInterceptorTest method testNotFirstLineNoLeadingSpaces.

/**
     * The input is a normal /* &#42;&#47; comment without leading spaces.
     */
@Ignore
@Test
public void testNotFirstLineNoLeadingSpaces() {
    doReturn("").when(document).getLineContent(0);
    doReturn("/*").when(document).getLineContent(1);
    doReturn(" *").when(document).getLineContent(2);
    final TextChange input = new TextChange.Builder().from(new TextPosition(1, 2)).to(new TextPosition(2, 2)).insert("\n *").build();
    final TextChange output = interceptor.processChange(input, document);
    assertNotNull(output);
    final TextChange expected = new TextChange.Builder().from(new TextPosition(1, 2)).to(new TextPosition(3, 3)).insert("\n * \n */").build();
    Assert.assertEquals(expected, output);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextChange(org.eclipse.che.ide.api.editor.changeintercept.TextChange) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with TextPosition

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

the class CloseCStyleCommentChangeInterceptorTest method testFirstLineNoLeadingSpaces.

@Ignore
@Test
public void testFirstLineNoLeadingSpaces() {
    doReturn("/*").when(document).getLineContent(0);
    doReturn(" *").when(document).getLineContent(1);
    final TextChange input = new TextChange.Builder().from(new TextPosition(0, 2)).to(new TextPosition(1, 2)).insert("\n *").build();
    final TextChange output = interceptor.processChange(input, document);
    assertNotNull(output);
    final TextChange expected = new TextChange.Builder().from(new TextPosition(0, 2)).to(new TextPosition(2, 3)).insert("\n * \n */").build();
    Assert.assertEquals(expected, output);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextChange(org.eclipse.che.ide.api.editor.changeintercept.TextChange) Ignore(org.junit.Ignore) Test(org.junit.Test)

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