Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1376)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui.web/src/com/google/dart/tools/ui/web/html/HtmlAutoIndentStrategy.java

Issue 11673007: Improve our html editor; add syntax highlighting for script tags; hyperlink detection and navigatio… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.ui.web/src/com/google/dart/tools/ui/web/html/HtmlAutoIndentStrategy.java
===================================================================
--- editor/tools/plugins/com.google.dart.tools.ui.web/src/com/google/dart/tools/ui/web/html/HtmlAutoIndentStrategy.java (revision 16584)
+++ editor/tools/plugins/com.google.dart.tools.ui.web/src/com/google/dart/tools/ui/web/html/HtmlAutoIndentStrategy.java (working copy)
@@ -14,6 +14,7 @@
package com.google.dart.tools.ui.web.html;
+import com.google.dart.tools.core.html.HtmlKeywords;
import com.google.dart.tools.ui.web.utils.WebEditorAutoIndentStrategy;
import org.eclipse.jface.text.BadLocationException;
@@ -24,7 +25,7 @@
/**
* An indent strategy for html.
*/
-public class HtmlAutoIndentStrategy extends WebEditorAutoIndentStrategy {
+class HtmlAutoIndentStrategy extends WebEditorAutoIndentStrategy {
public HtmlAutoIndentStrategy() {
@@ -55,16 +56,52 @@
buf.append(document.get(start, end - start));
}
- // Indent after a >+eol, but not if we're closing an element tag.
- if (endsInBracket && !(startStr.contains("</") || startStr.contains("/>"))
- && !(startStr.toLowerCase().endsWith("<p>"))) {
- buf.append(" ");
+ if (endsInBracket) {
+ // handle self-closing tags
+ String startTagName = getStartTagName(startStr);
+
+ boolean selfClosing = (startTagName != null && HtmlKeywords.isSelfClosing(startTagName.toLowerCase()));
+
+ if (!selfClosing) {
+ if (startStr.indexOf('<') != -1) {
+ startStr = startStr.substring(startStr.lastIndexOf('<'));
+ }
+
+ // Indent after an ">", but not if we're closing an element tag.
+ if (!(startStr.startsWith("</") || startStr.endsWith("/>"))) {
+ buf.append(" ");
+ }
+ }
}
command.text = buf.toString();
} catch (BadLocationException excp) {
- // stop work
+
}
}
+ private String getStartTagName(String line) {
+ String tag = line;
+
+ if (tag.indexOf('<') != -1) {
+ tag = tag.substring(tag.lastIndexOf('<'));
+ }
+
+ if (tag.startsWith("<")) {
+ StringBuilder builder = new StringBuilder();
+
+ for (int i = 1; i < tag.length(); i++) {
+ if (!Character.isJavaIdentifierPart(tag.charAt(i))) {
+ return builder.toString();
+ } else {
+ builder.append(tag.charAt(i));
+ }
+ }
+
+ return builder.toString();
+ } else {
+ return null;
+ }
+ }
+
}

Powered by Google App Engine
This is Rietveld 408576698