1 package winterwell.markdown.editors;
3 import org.eclipse.core.runtime.NullProgressMonitor;
4 import org.eclipse.jface.preference.IPreferenceStore;
5 import org.eclipse.jface.text.IDocument;
6 import org.eclipse.jface.text.IRegion;
7 import org.eclipse.jface.text.ITextHover;
8 import org.eclipse.jface.text.presentation.IPresentationReconciler;
9 import org.eclipse.jface.text.presentation.PresentationReconciler;
10 import org.eclipse.jface.text.reconciler.DirtyRegion;
11 import org.eclipse.jface.text.reconciler.IReconciler;
12 import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
13 import org.eclipse.jface.text.reconciler.MonoReconciler;
14 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
15 import org.eclipse.jface.text.source.ISourceViewer;
16 import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
18 public class MDConfiguration extends TextSourceViewerConfiguration {
19 private ColorManager colorManager;
21 public MDConfiguration(ColorManager colorManager, IPreferenceStore prefStore) {
23 this.colorManager = colorManager;
27 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
28 MDScanner scanner = new MDScanner(colorManager);
29 PresentationReconciler pr = (PresentationReconciler) super.getPresentationReconciler(sourceViewer); // FIXME
30 DefaultDamagerRepairer ddr = new DefaultDamagerRepairer(scanner);
31 pr.setRepairer(ddr, IDocument.DEFAULT_CONTENT_TYPE);
32 pr.setDamager(ddr, IDocument.DEFAULT_CONTENT_TYPE);
38 public IReconciler getReconciler(ISourceViewer sourceViewer) {
39 // This awful mess adds in update support
41 IReconciler rs = super.getReconciler(sourceViewer);
42 if (true) return rs; // Seems to work fine?!
43 final IReconcilingStrategy fsuperStrategy = rs==null? null : rs.getReconcilingStrategy("text");
45 IReconcilingStrategy strategy = new IReconcilingStrategy() {
46 private IDocument doc;
47 public void reconcile(IRegion partition) {
48 MarkdownEditor ed = MarkdownEditor.getEditor(doc);
49 if (ed != null) ed.updatePage(partition);
50 if (fsuperStrategy!=null) fsuperStrategy.reconcile(partition);
52 public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
53 MarkdownEditor ed = MarkdownEditor.getEditor(doc);
54 if (ed != null) ed.updatePage(subRegion);
55 if (fsuperStrategy!=null) fsuperStrategy.reconcile(dirtyRegion, subRegion);
57 public void setDocument(IDocument document) {
59 if (fsuperStrategy!=null) fsuperStrategy.setDocument(document);
63 MonoReconciler m2 = new MonoReconciler(strategy, true);
64 m2.setIsIncrementalReconciler(true);
65 m2.setProgressMonitor(new NullProgressMonitor());
71 @SuppressWarnings("unused")
73 public ITextHover getTextHover(ISourceViewer sourceViewer,
75 if (true) return super.getTextHover(sourceViewer, contentType);
76 // Add hover support for images
77 return new MDTextHover();