CFMLEditor thisEdit = (CFMLEditor) activeEditor;
IDocument doc = thisEdit.getDocumentProvider().getDocument(thisEdit.getEditorInput());
ISelection sel = thisEdit.getSelectionProvider().getSelection();
DocItem docItem = thisEdit.getSelectionCursorListener().getSelectedTag();
if (docItem != null && docItem instanceof CfmlTagItem) {
CfmlTagItem tagItem = (CfmlTagItem) docItem;
int tagStart = tagItem.getStartPosition();
int tagEnd = tagItem.getEndPosition();
TextSelection selection;
int startPos = tagItem.getStartPosition();
int endPos = tagItem.getEndPosition();
int start = 0;
int length = 0;
if(tagItem.matchingItem != null) {
if (tagItem.matchingItem.getStartPosition() < tagItem.getStartPosition()) {
start = tagItem.matchingItem.getStartPosition();
length = tagItem.getEndPosition() - tagItem.matchingItem.getStartPosition() + 1;
} else {
start = tagItem.getStartPosition();
length = tagItem.matchingItem.getEndPosition() - tagItem.getStartPosition() + 1;
}
} else {
if (tagItem.matchingItem != null && tagItem.matchingItem.getStartPosition() <= startPos
&& tagItem.matchingItem.getEndPosition() >= startPos) {
start = tagItem.matchingItem.getStartPosition();
length = tagItem.matchingItem.getEndPosition() - tagItem.matchingItem.getStartPosition() + 1;
} else {
start = tagItem.getStartPosition();
length = tagItem.getEndPosition() - tagItem.getStartPosition() + 1;
}
}
// thisEdit.selectAndReveal(tagStart,tagEnd-tagStart+1);
selection = new TextSelection(start, length);
ISelectionProvider selectionProvider = thisEdit.getSelectionProvider();
selectionProvider.setSelection(selection);
/*
* Get the actual textual content of the tag
*/
String tagText = "";
try {
tagText = doc.get(selection.getOffset(), selection.getLength());
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
/*
* Get the attributes as a map TODO: I am not sure if map's keep the
* ordering... need to check this
*/
Map attributeMap = CFDocUtils.parseStartTag(tagItem.getName(), tagText);
/*
* Now open the TagEditDialog, we know the tag name (as a string)
* and the tag attributes (as a map) So, we go and get the tag from
* the dictionary
*/
Tag tagToEdit = DictionaryManager.getDictionary("CF_DICTIONARY").getTag(tagItem.getName());
/*
* Setup the tageditor dialog
*/
TagEditDialog tagview = new TagEditDialog(shell, tagToEdit);