Search in sources :

Example 41 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project intellij-code-outline by sitano.

the class CodeOutlineImageEx method renderRestOfLineToImg.

/**
 * Renders the characters at the given document offset to the code outline
 * image until the first newline character is reached or until the right
 * edge of the image is reached and no more characters can be rendered.
 *
 * @param startOff the offset into the document at which to start rendering
 * @return how many characters were rendered, not including the newline
 */
@Override
protected int renderRestOfLineToImg(int startOff) {
    final CharSequence chars = document.getCharsSequence();
    final int endOff = document.getTextLength();
    if (startOff >= endOff)
        return 0;
    final LogicalPosition startPos = editor.offsetToLogicalPosition(startOff);
    final int line = startPos.line;
    final EditorEx ex = (EditorEx) editor;
    final EditorHighlighter hl = ex.getHighlighter();
    final HighlighterIterator hi = hl.createIterator(startOff);
    int col = startPos.column;
    int painted = 0;
    for (int i = startOff; i < endOff; i++) {
        final char ch = chars.charAt(i);
        while (!hi.atEnd() && i > hi.getEnd()) {
            hi.advance();
        }
        if (ch == '\n')
            break;
        if (col >= visibleImgWidth)
            break;
        drawChar(ch, col, line, getCharColor(editor, hi));
        painted++;
        col++;
    }
    return painted;
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 42 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project WebStormRequireJsPlugin by Fedott.

the class CompletionPathWithTwoDotTest method testCompletionWithTwoDot.

public void testCompletionWithTwoDot() {
    // WithTwoDot
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 38));
    myFixture.complete(CompletionType.BASIC, 1);
    List<String> strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.containsAll(Arrays.asList("../main", "../rootWebPathFile", "../blocks/block", "../blocks/childWebPathFile", "../blocks/fileWithDotPath", "../blocks/fileWithTwoDotPath", "../blocks/childBlocks/childBlock")));
    assertEquals(7, strings.size());
    // WithTwoDotAndSlash
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 47));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assertTrue(strings.containsAll(Arrays.asList("../main", "../rootWebPathFile", "../blocks/block", "../blocks/childWebPathFile", "../blocks/fileWithDotPath", "../blocks/fileWithTwoDotPath", "../blocks/childBlocks/childBlock")));
    assertEquals(7, strings.size());
    // WithTwoDotAndSlashTwoChars
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(3, 57));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assertTrue(strings.containsAll(Arrays.asList("../blocks/block", "../blocks/childWebPathFile", "../blocks/fileWithDotPath", "../blocks/fileWithTwoDotPath", "../blocks/childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // WithTwoDotAndDirectory
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 57));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assertTrue(strings.containsAll(Arrays.asList("../blocks/block", "../blocks/childWebPathFile", "../blocks/fileWithDotPath", "../blocks/fileWithTwoDotPath", "../blocks/childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // WithTwoDotAndDirectoryAndSlash
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 66));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assertTrue(strings.containsAll(Arrays.asList("../blocks/block", "../blocks/childWebPathFile", "../blocks/fileWithDotPath", "../blocks/fileWithTwoDotPath", "../blocks/childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // WithTwoDotAndTwoDirectories
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(6, 74));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("../blocks/childBlocks/childBlock");
    // WithTwoDotAndTwoDirectoriesAndSlash
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(7, 83));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("../blocks/childBlocks/childBlock");
    // WithTwoDotAndDirectoryAndSlashTwoChars
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(8, 77));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("../blocks/block");
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Example 43 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project WebStormRequireJsPlugin by Fedott.

the class CompletionPathWithTwoDotTest method testCompletionTwoTwoDotPath.

public void testCompletionTwoTwoDotPath() {
    myFixture.configureByFile("public/blocks/childBlocks/fileWithTwoDotPathChild.js");
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 39));
    myFixture.complete(CompletionType.BASIC, 1);
    List<String> strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.containsAll(Arrays.asList("../../blocks/block", "../../blocks/childWebPathFile", "../../blocks/fileWithDotPath", "../../blocks/fileWithTwoDotPath", "../../blocks/childBlocks/childBlock", "../../blocks/childBlocks/fileWithTwoDotPathChild")));
    assertEquals(6, strings.size());
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 50));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.isEmpty());
    assertEquals(0, strings.size());
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Example 44 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project WebStormRequireJsPlugin by Fedott.

the class ConfigParseTest method testReference.

public void testReference() {
    Settings.getInstance(getProject()).configFilePath = "mainRequireJs.js";
    PsiReference reference;
    PsiElement referenceElement;
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 36));
    reference = myFixture.getReferenceAtCaretPosition();
    assert (reference) != null;
    reference = ((PsiMultiReference) reference).getReferences()[1];
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'module'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertEquals("rootWebPathConfigTest.js", ((JSFile) referenceElement).getName());
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 36));
    reference = myFixture.getReferenceAtCaretPosition();
    assert (reference) != null;
    reference = ((PsiMultiReference) reference).getReferences()[1];
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'moduleR'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertNull(referenceElement);
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(3, 51));
    reference = myFixture.getReferenceAtCaretPosition();
    assert (reference) != null;
    reference = ((PsiMultiReference) reference).getReferences()[1];
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'moduleRelativeBaseUrlPath'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertTrue(referenceElement instanceof JSFile);
    assertEquals("childBlock.js", ((JSFile) referenceElement).getName());
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 51));
    reference = myFixture.getReferenceAtCaretPosition();
    assert (reference) != null;
    reference = ((PsiMultiReference) reference).getReferences()[1];
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'moduleAbsolutePath'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertTrue(referenceElement instanceof JSFile);
    assertEquals("block.js", ((JSFile) referenceElement).getName());
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 51));
    reference = myFixture.getReferenceAtCaretPosition();
    assert (reference) != null;
    reference = ((PsiMultiReference) reference).getReferences()[1];
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'moduleRelativeOneDotPath'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertTrue(referenceElement instanceof JSFile);
    assertEquals("block.js", ((JSFile) referenceElement).getName());
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(6, 51));
    reference = myFixture.getReferenceAtCaretPosition();
    assert (reference) != null;
    reference = ((PsiMultiReference) reference).getReferences()[1];
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'moduleRelativeTwoDotPAth'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertNull(referenceElement);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) PsiReference(com.intellij.psi.PsiReference) PsiMultiReference(com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiElement(com.intellij.psi.PsiElement)

Example 45 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project WebStormRequireJsPlugin by Fedott.

the class ReferenceTest method testReference.

public void testReference() {
    PsiReference reference;
    PsiElement referenceElement;
    // referenceNotFound
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 40));
    reference = myFixture.getReferenceAtCaretPosition();
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'app/as'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertNull(referenceElement);
    // referenceTrue
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 40));
    reference = myFixture.getReferenceAtCaretPosition();
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'blocks/block'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertTrue(referenceElement instanceof JSFile);
    assertEquals("block.js", ((JSFile) referenceElement).getName());
    // referenceNotFound2
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(3, 40));
    reference = myFixture.getReferenceAtCaretPosition();
    assertTrue(reference instanceof PsiMultiReference);
    reference = ((PsiMultiReference) reference).getReferences()[1];
    assertEquals("'bl'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertNull(referenceElement);
    // referenceDirectory
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 40));
    reference = myFixture.getReferenceAtCaretPosition();
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'blocks/childBlocks'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertNull(referenceElement);
    // referenceWithTwoDot
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 46));
    reference = myFixture.getReferenceAtCaretPosition();
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'../blocks/block'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertTrue(referenceElement instanceof JSFile);
    assertEquals("block.js", ((JSFile) referenceElement).getName());
    // referenceWithTwoDotTwoDir
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(6, 49));
    reference = myFixture.getReferenceAtCaretPosition();
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'../blocks/childBlocks/childBlock'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertTrue(referenceElement instanceof JSFile);
    assertEquals("childBlock.js", ((JSFile) referenceElement).getName());
    // referenceWithOneDot
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(7, 44));
    reference = myFixture.getReferenceAtCaretPosition();
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'./block'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertTrue(referenceElement instanceof JSFile);
    assertEquals("block.js", ((JSFile) referenceElement).getName());
    // referenceWithOneDotTwoDir
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(8, 50));
    reference = myFixture.getReferenceAtCaretPosition();
    assertTrue(reference instanceof RequirejsReference);
    assertEquals("'./childBlocks/childBlock'", reference.getCanonicalText());
    referenceElement = reference.resolve();
    assertTrue(referenceElement instanceof JSFile);
    assertEquals("childBlock.js", ((JSFile) referenceElement).getName());
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) PsiReference(com.intellij.psi.PsiReference) PsiMultiReference(com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

LogicalPosition (com.intellij.openapi.editor.LogicalPosition)106 Document (com.intellij.openapi.editor.Document)16 PsiElement (com.intellij.psi.PsiElement)14 Editor (com.intellij.openapi.editor.Editor)12 TextRange (com.intellij.openapi.util.TextRange)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 CaretModel (com.intellij.openapi.editor.CaretModel)6 NotNull (org.jetbrains.annotations.NotNull)6 RelativePoint (com.intellij.ui.awt.RelativePoint)5 JSFile (com.intellij.lang.javascript.psi.JSFile)4 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)4 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 PsiReference (com.intellij.psi.PsiReference)4 PsiMultiReference (com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference)4 Mark (com.maddyhome.idea.vim.common.Mark)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 EditorWindow (com.intellij.injected.editor.EditorWindow)3