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