Completely changed the structure and switched to Eclipse Plugin.
[Mograsim.git] / net.mograsim.plugin.core / src / net / mograsim / plugin / asm / editor / AsmAutoEditStrategy.java
diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmAutoEditStrategy.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/editor/AsmAutoEditStrategy.java
new file mode 100644 (file)
index 0000000..7198a27
--- /dev/null
@@ -0,0 +1,38 @@
+package net.mograsim.plugin.asm.editor;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+
+public class AsmAutoEditStrategy implements IAutoEditStrategy
+{
+
+       @Override
+       public void customizeDocumentCommand(IDocument document, DocumentCommand command)
+       {
+               if (!">".equals(command.text))
+               { // NON-NLS-1
+                       return;
+               }
+               try
+               {
+                       IRegion region = document.getLineInformationOfOffset(command.offset);
+                       String line = document.get(region.getOffset(), command.offset - region.getOffset());
+                       int index = line.lastIndexOf('<');
+                       if (index != -1 && (index != line.length() - 1) && line.charAt(index + 1) != '/')
+                       {
+                               String tag = line.substring(index + 1);
+                               command.caretOffset = command.offset + 1;
+                               command.text += "</" + tag + command.text; // NON-NLS-1
+                               command.shiftsCaret = false;
+                       }
+               }
+               catch (BadLocationException e)
+               {
+                       // ignore
+               }
+       }
+
+}