views:

53

answers:

2

I am currently working on a custom editor plugin for Eclipse. I've overwritten getAutoEditStrategies like this:

public IAutoEditStrategy[] getAutoEditStrategies(
  ISourceViewer sourceViewer, String contentType) {
  return new IAutoEditStrategy[] { new KRLAutoEditStrategy() };
}

and written a minimal Strategy like this:

public class KRLAutoEditStrategy implements IAutoEditStrategy {
  public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
    System.out.println("Called.");
  }
}

Now customizeDocumentCommand is only called when I hit backspace, not for any other character. What am I missing? How else do I implement auto indention?

+1  A: 

Can't see anything wrong with your custom strategy (almost the same code works fine for me), but to implement some basic kind of auto indention you can use DefaultIndentLineAutoEditStrategy (add it to the array returned by getAutoEditStrategies)

axtavt
A: 

I've actually figured this one out myself now. My strategy was perfectly fine but it didn't work because the editor partition I wanted it to be applied to was not exposed through getConfiguredContentTypes.

When your coloring or indention doesn't work, make sure that you work on a partition which has the correct tokens applied to it and exposed through getConfiguredContentTypes! The problem became obvious when I used distinct colors for all partitions and one of them didn't get colored.

Henrik