use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class HighlighterUtil method formatTooltip.
private static Object formatTooltip(Editor e, PsiElement element) {
if (!(element instanceof XmlTag)) {
final String text = element.getText();
if ((text == null || text.length() == 0) && MyPsiUtil.isNameElement(element)) {
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, true);
if (tag != null) {
return tag.getName();
}
}
return text;
}
// have to use html/preformatted or else the tooltip gets formatted totally weird.
final CodeStyleSettingsManager instance = CodeStyleSettingsManager.getInstance(element.getProject());
final int tabSize = instance.getCurrentSettings().getTabSize(FileTypeManager.getInstance().getFileTypeByExtension("xml"));
final char[] spaces = new char[tabSize];
for (int i = 0; i < spaces.length; i++) {
spaces[i] = ' ';
}
final int textOffset = element.getTextOffset();
final int lineStartOffset = e.logicalPositionToOffset(new LogicalPosition(e.offsetToLogicalPosition(textOffset).line, 0));
final CharSequence chars = e.getDocument().getCharsSequence();
int indent = 0;
for (int i = lineStartOffset; i < textOffset; i++) {
if (chars.charAt(i) == ' ') {
indent++;
} else if (chars.charAt(i) == '\t') {
indent += ((indent + tabSize) / tabSize) * tabSize - indent;
} else {
break;
}
}
final String text = element.getText().replaceAll("\\t", new String(spaces)).replaceAll("&", "&").replaceAll("<", "<");
final Pattern indentPattern = Pattern.compile("^(\\s*).+");
final StringBuilder sb = new StringBuilder("<html><pre>");
final String[] lines = text.split("\\n");
for (String line : lines) {
final Matcher matcher = indentPattern.matcher(line);
if (matcher.matches()) {
// strip off the amount of spaces the top-level element is indented with
line = line.substring(Math.min(matcher.group(1).length(), indent));
}
sb.append(line).append("\n");
}
return sb.append("</pre></html>").toString();
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class PyEditingTest method testGreedyBackspace.
public void testGreedyBackspace() {
// PY-254
final EditorSettingsExternalizable settings = EditorSettingsExternalizable.getInstance();
boolean oldVSpaceValue = settings.isVirtualSpace();
try {
settings.setVirtualSpace(true);
doTestBackspace("py254", new LogicalPosition(4, 8));
} finally {
settings.setVirtualSpace(oldVSpaceValue);
}
}
use of com.intellij.openapi.editor.LogicalPosition in project android by JetBrains.
the class AndroidValueResourcesTest method testNavigationInPlatformXml2_NavigateFromNameAttr.
public void testNavigationInPlatformXml2_NavigateFromNameAttr() throws Exception {
VirtualFile themes_holo = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes_holo.xml").toString());
assertNotNull(themes_holo);
VirtualFile themes = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes.xml").toString());
assertNotNull(themes);
// In themes_holo.xml: point to value of "Theme" in the name attribute on line:
// <style name="Theme.Holo.NoActionBar">
// Goto action should navigate to "Theme" in themes.xml, on line: "<style name="Theme">"
myFixture.configureFromExistingVirtualFile(themes_holo);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(776, 19));
PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
assertInstanceOf(targetElement, XmlAttributeValue.class);
XmlAttributeValue targetAttrValue = (XmlAttributeValue) targetElement;
assertEquals("Theme", targetAttrValue.getValue());
assertEquals("name", ((XmlAttribute) targetAttrValue.getParent()).getName());
assertEquals("style", ((XmlTag) targetAttrValue.getParent().getParent()).getName());
assertEquals(themes, targetElement.getContainingFile().getVirtualFile());
}
use of com.intellij.openapi.editor.LogicalPosition in project android by JetBrains.
the class AndroidValueResourcesTest method testNavigationInPlatformXml1_NavigateFromParentAttr.
public void testNavigationInPlatformXml1_NavigateFromParentAttr() throws Exception {
VirtualFile themes_holo = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes_holo.xml").toString());
assertNotNull(themes_holo);
VirtualFile themes = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes.xml").toString());
assertNotNull(themes);
// In themes_holo.xml: point to value of "Theme" in the parent attribute on line:
// <style name="Theme.Holo.Light" parent="Theme.Light">
// Goto action should navigate to "Theme" in themes.xml, on line: "<style name="Theme">"
myFixture.configureFromExistingVirtualFile(themes_holo);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(406, 45));
PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
assertInstanceOf(targetElement, XmlAttributeValue.class);
XmlAttributeValue targetAttrValue = (XmlAttributeValue) targetElement;
assertEquals("Theme", targetAttrValue.getValue());
assertEquals("name", ((XmlAttribute) targetAttrValue.getParent()).getName());
assertEquals("style", ((XmlTag) targetAttrValue.getParent().getParent()).getName());
assertEquals(themes, targetElement.getContainingFile().getVirtualFile());
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-plugins by JetBrains.
the class ActionUtil method getCodePointer.
static CodePointer getCodePointer(Editor editor) {
CodePointer codePointer;
int selectionStart = editor.getSelectionModel().getSelectionStart();
int selectionEnd = editor.getSelectionModel().getSelectionEnd();
if (selectionStart != selectionEnd) {
LogicalPosition start = editor.offsetToLogicalPosition(selectionStart);
LogicalPosition end = editor.offsetToLogicalPosition(selectionEnd);
codePointer = new CodePointer(start.line, start.column, end.line, end.column);
} else {
LogicalPosition pos = editor.getCaretModel().getLogicalPosition();
codePointer = new CodePointer(pos.line, pos.column);
}
return codePointer;
}
Aggregations