public void run(Result result, SchedulerEvent event) {
lastResult = (LyParserResult) result;
if (event instanceof CursorMovedSchedulerEvent) {
CursorMovedSchedulerEvent evt = (CursorMovedSchedulerEvent) event;
NbEditorDocument document = (NbEditorDocument) result.getSnapshot().getSource().getDocument(false);
String checktab = result.getSnapshot().getText().toString();
if (checktab.indexOf("\t") >= 0) {
try {
document.remove(0, document.getLength());
document.insertString(0, checktab.replace("\t", " "), null);
} catch (Exception ex) {
}
}
//if cursor was set with temp then this cursor should not be destroyed
if (getLastCurrent() != null && (getLastCurrent().id == ParserTreeConstants.JJTTEMPNODE ||getLastCurrent().id==ParserTreeConstants.JJTLINEBEGIN) ) {
int col = NbDocument.findLineColumn(document, evt.getCaretOffset())+1;
int line = NbDocument.findLineNumber(document, evt.getCaretOffset())+1;
if(getLastCurrent().jjtGetFirstToken().beginColumn==col&&getLastCurrent().jjtGetFirstToken().beginLine==line)
return;
}
SimpleNode ret = find(document, lastResult.getRoot(), evt.getCaretOffset(), evt.getMarkOffset());
if(ret!=null&&ret.jjtGetParent()!=null&&ret.jjtGetParent().id==ParserTreeConstants.JJTKEY)
ret=ret.jjtGetParent();
if (ret == null || (ret.jjtGetNumChildren() > 0 && ret.id!=ParserTreeConstants.JJTKEY)) {
try {
//find last valid node
SimpleNode singleNode=ret;
int ct=evt.getCaretOffset();
while(ct>0&& singleNode.jjtGetNumChildren()!=0){
singleNode=find(document, lastResult.getRoot(),ct, 0);
ct--;
}
int col = NbDocument.findLineColumn(document, evt.getCaretOffset())+1;
int line = NbDocument.findLineNumber(document, evt.getCaretOffset());
ASTTempNode gen = ASTTempNode.create(document.getText(evt.getCaretOffset(), 1), line, col,singleNode);
ret = gen;
} catch (Exception ex) {
ex.printStackTrace();
}
}