if (selection != null && selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection)selection;
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
if (doc != null) {
try {
ITypedRegion region = doc.getPartition(textSelection.getOffset());
// comment handling for TMLScriptEditor
if (editorPart instanceof TMLScriptEditor) {
if (region.getType().equals(TMLScriptPartitionScanner.MCOMMENT)) {
removeTMLScriptComment(doc, region);
} else if(editorPart instanceof TMLScriptEditor){
createTMLScriptComment(doc, textSelection);
}
}
// comment handling for TMLEditor
if(editorPart instanceof TMLEditor){
// remove comments if we are already in a comment section
if(region.getType().equals(TMLScriptPartitionScanner.MCOMMENT)) {
removeTMLScriptComment(doc, region);
}
if(region.getType().equals(TMLPartitionScanner.TML_COMMENT)) {
removeTMLComment(doc, region);
}
// create comments depending on current partition
if(region.getType().equals(TMLScriptPartitionScanner.TMLSCRIPT)){
createTMLScriptComment(doc, textSelection);
} else {
createTMLComment(doc, textSelection);
}
}