Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / corext / template / php / HTMLUnitContext.java
index c9abf99..136e438 100644 (file)
@@ -9,6 +9,7 @@ import net.sourceforge.phpdt.internal.corext.template.DocumentTemplateContext;
 import net.sourceforge.phpdt.internal.corext.template.Template;
 import net.sourceforge.phpdt.internal.corext.template.TemplateBuffer;
 import net.sourceforge.phpdt.internal.corext.template.TemplateTranslator;
+
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
@@ -21,10 +22,17 @@ public class HTMLUnitContext extends DocumentTemplateContext {
   /** The platform default line delimiter. */
   private static final String PLATFORM_LINE_DELIMITER = System.getProperty("line.separator"); //$NON-NLS-1$
 
-  private static final String specialChars = "&<#";
+  /** special characters
+   * '&' for the start of HTML entities
+   * '<' for the start of HTML tags
+   * '#' for the start of colour attributes
+   * '{' for the start of smarty partitions inside HTML code
+   */
+  private static final String specialChars = "&<#{";
+
   /** The compilation unit, may be <code>null</code>. */
   //   private final ICompilationUnit fCompilationUnit;
-
+  protected boolean fForceEvaluation;
   /**
    * Creates a compilation unit context.
    * 
@@ -36,7 +44,7 @@ public class HTMLUnitContext extends DocumentTemplateContext {
   protected HTMLUnitContext(ContextType type, IDocument document, int completionPosition)
   //,ICompilationUnit compilationUnit)
   {
-    super(type, document, completionPosition);
+    super(type, document, completionPosition, 0);
     // fCompilationUnit= compilationUnit;
   }
 
@@ -93,22 +101,44 @@ public class HTMLUnitContext extends DocumentTemplateContext {
   public int getStart() {
     IDocument document = getDocument();
     try {
-      int start = getCompletionPosition();
-
-      while (((start != 0) && Character.isUnicodeIdentifierPart(document.getChar(start - 1)))
-        || ((start != 0) && specialChars.indexOf(document.getChar(start - 1)) != (-1) )) {
-        start--;
+      int start = getCompletionOffset();
+      char ch = ' ';
+      while (start != 0) {
+        ch = document.getChar(start - 1);
+        if (specialChars.indexOf(ch) != (-1)) {
+          return --start;
+        }
+        if (Character.isUnicodeIdentifierPart(ch)) {
+          start--;
+        } else {
+          break;
+        }
       }
-
-      if (((start != 0) && Character.isUnicodeIdentifierStart(document.getChar(start - 1)))
-        || ((start != 0) && specialChars.indexOf(document.getChar(start - 1)) != (-1) )) {
+      if ((start != 0) && Character.isUnicodeIdentifierStart(document.getChar(start - 1))) {
         start--;
+        if ((start != 0) && specialChars.indexOf(document.getChar(start - 1)) != (-1)) {
+          start--;
+        }
       }
 
+      //      while (((start != 0)
+      //        && Character.isUnicodeIdentifierPart(document.getChar(start - 1)))
+      //        || ((start != 0)
+      //          && specialChars.indexOf(document.getChar(start - 1)) != (-1))) {
+      //        start--;
+      //      }
+      //
+      //if (((start != 0)
+      //       && Character.isUnicodeIdentifierStart(document.getChar(start - 1)))
+      //       || ((start != 0)
+      //               && specialChars.indexOf(document.getChar(start - 1)) != (-1))) {
+      //       start--;
+      //}
+
       return start;
 
     } catch (BadLocationException e) {
-      return getCompletionPosition();
+      return getCompletionOffset();
     }
   }
 
@@ -151,5 +181,10 @@ public class HTMLUnitContext extends DocumentTemplateContext {
   //                   return null;
   //           }       
   //   }
-
+  /**
+   * Forces evaluation.
+   */
+  public void setForceEvaluation(boolean evaluate) {
+    fForceEvaluation = evaluate;
+  }
 }