if(editor != null && editor.isEditable())
{
SnipKeyCombos keyCombos = new SnipKeyCombos();
String sequence = "";
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
ISelection sel = editor.getSelectionProvider().getSelection();
int cursorOffset = ((ITextSelection)sel).getOffset();
int lastSpaceOffset = -1;
//int nextSpaceOffset = -1;
FindReplaceDocumentAdapter finder = new FindReplaceDocumentAdapter(doc);
try {
IRegion lastSpace = finder.find(cursorOffset-1,"[^\\*0-9a-zA-Z_-]",false,false,false,true);
if (lastSpace == null) {
lastSpaceOffset = 0;
}
else {
lastSpaceOffset = lastSpace.getOffset()+1;
}
// System.out.println("Last Space at" + lastSpaceOffset);
// System.out.println("Cursot at" + cursorOffset);
if (cursorOffset > lastSpaceOffset) {
// ok, it could be valid, but we need to check what comes after the cursor.
if (cursorOffset != doc.getLength()) {
System.out.println("yep");
IRegion nextSpace = finder.find(cursorOffset-1,"[^\\*0-9a-zA-Z_-]",true,false,false,true);
if (nextSpace != null
&& nextSpace.getOffset() == cursorOffset) {
//System.out.println("Next space bit");
sequence = doc.get().substring(lastSpaceOffset,cursorOffset);
}
}
else {
sequence = doc.get().substring(lastSpaceOffset,cursorOffset);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
if(sequence.length() == 0){
System.out.println("no trigger text has been passed in");
}
if (sequence.length() > 0) {
String[] stringArray = sequence.split("\\*");
String trigger = stringArray[0];
int loopcount = 1;
if (stringArray.length > 1) {
loopcount = Integer.parseInt(stringArray[1].trim());
}
//Here starts the actual triggering of a snippet using the trigger text
String fileName = keyCombos.getKeyCombo(trigger);
SnipReader snipReader = new SnipReader();