From e5bb15070a0a3ce511125ca4b6e063210d96a3f2 Mon Sep 17 00:00:00 2001 From: Alexander Doroshko Date: Thu, 13 Dec 2012 16:12:45 +0400 Subject: [PATCH] normalize spaces and do not surround with () --- .../HtmlStructureViewElementProvider.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/xml/impl/src/com/intellij/lang/html/HtmlStructureViewElementProvider.java b/xml/impl/src/com/intellij/lang/html/HtmlStructureViewElementProvider.java index d311e717a70c..87717f089698 100644 --- a/xml/impl/src/com/intellij/lang/html/HtmlStructureViewElementProvider.java +++ b/xml/impl/src/com/intellij/lang/html/HtmlStructureViewElementProvider.java @@ -5,6 +5,7 @@ import com.intellij.ide.highlighter.HtmlFileType; import com.intellij.ide.structureView.StructureViewTreeElement; import com.intellij.ide.structureView.impl.xml.XmlTagTreeElement; import com.intellij.ide.structureView.xml.XmlStructureViewElementProvider; +import com.intellij.navigation.LocationPresentation; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.xml.XmlTag; import org.jetbrains.annotations.NotNull; @@ -24,7 +25,7 @@ public class HtmlStructureViewElementProvider implements XmlStructureViewElement return new HtmlTagTreeElement(tag); } - static class HtmlTagTreeElement extends XmlTagTreeElement { + static class HtmlTagTreeElement extends XmlTagTreeElement implements LocationPresentation { public HtmlTagTreeElement(final XmlTag tag) { super(tag); } @@ -55,10 +56,27 @@ public class HtmlStructureViewElementProvider implements XmlStructureViewElement final XmlTag tag = getElement(); if (tag == null) return null; - final String text = tag.getValue().getTrimmedText(); + final String text = normalizeSpaces(tag.getValue().getTrimmedText()); return text.isEmpty() ? null : shortenTextIfLong(text); } + private static String normalizeSpaces(final String text) { + final StringBuilder buf = new StringBuilder(); + + for (char ch : text.toCharArray()) { + if (ch <= ' ' || Character.isSpaceChar(ch)) { + if (buf.length() == 0 || buf.charAt(buf.length() - 1) != ' ') { + buf.append(' '); + } + } + else { + buf.append(ch); + } + } + + return buf.toString(); + } + private static String shortenTextIfLong(final String text) { if (text.length() < MAX_TEXT_LENGTH) return text; @@ -72,5 +90,13 @@ public class HtmlStructureViewElementProvider implements XmlStructureViewElement final int endIndex = Character.isLetter(index) ? MAX_TEXT_LENGTH : index; return text.substring(0, endIndex) + "..."; } + + public String getLocationPrefix() { + return " "; + } + + public String getLocationSuffix() { + return ""; + } } }