X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Fwinterwell.markdown%2Fsrc%2Fwinterwell%2Fmarkdown%2Feditors%2FMDConfiguration.java;fp=bundles%2Fwinterwell.markdown%2Fsrc%2Fwinterwell%2Fmarkdown%2Feditors%2FMDConfiguration.java;h=f20a64277dc819266bdb0435703531709f032159;hb=2531cdf245f42bce854d43f4d49a23983c79db96;hp=0000000000000000000000000000000000000000;hpb=857dbc869796d772864327ce02f19dc252b159fc;p=simantics%2Fplatform.git diff --git a/bundles/winterwell.markdown/src/winterwell/markdown/editors/MDConfiguration.java b/bundles/winterwell.markdown/src/winterwell/markdown/editors/MDConfiguration.java new file mode 100644 index 000000000..f20a64277 --- /dev/null +++ b/bundles/winterwell.markdown/src/winterwell/markdown/editors/MDConfiguration.java @@ -0,0 +1,81 @@ +package winterwell.markdown.editors; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextHover; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.reconciler.DirtyRegion; +import org.eclipse.jface.text.reconciler.IReconciler; +import org.eclipse.jface.text.reconciler.IReconcilingStrategy; +import org.eclipse.jface.text.reconciler.MonoReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; + +public class MDConfiguration extends TextSourceViewerConfiguration { + private ColorManager colorManager; + + public MDConfiguration(ColorManager colorManager, IPreferenceStore prefStore) { + super(prefStore); + this.colorManager = colorManager; + } + + @Override + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + MDScanner scanner = new MDScanner(colorManager); + PresentationReconciler pr = (PresentationReconciler) super.getPresentationReconciler(sourceViewer); // FIXME + DefaultDamagerRepairer ddr = new DefaultDamagerRepairer(scanner); + pr.setRepairer(ddr, IDocument.DEFAULT_CONTENT_TYPE); + pr.setDamager(ddr, IDocument.DEFAULT_CONTENT_TYPE); + return pr; + } + + + @Override + public IReconciler getReconciler(ISourceViewer sourceViewer) { + // This awful mess adds in update support + // Get super strategy + IReconciler rs = super.getReconciler(sourceViewer); + if (true) return rs; // Seems to work fine?! + final IReconcilingStrategy fsuperStrategy = rs==null? null : rs.getReconcilingStrategy("text"); + // Add our own + IReconcilingStrategy strategy = new IReconcilingStrategy() { + private IDocument doc; + public void reconcile(IRegion partition) { + MarkdownEditor ed = MarkdownEditor.getEditor(doc); + if (ed != null) ed.updatePage(partition); + if (fsuperStrategy!=null) fsuperStrategy.reconcile(partition); + } + public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) { + MarkdownEditor ed = MarkdownEditor.getEditor(doc); + if (ed != null) ed.updatePage(subRegion); + if (fsuperStrategy!=null) fsuperStrategy.reconcile(dirtyRegion, subRegion); + } + public void setDocument(IDocument document) { + this.doc = document; + if (fsuperStrategy!=null) fsuperStrategy.setDocument(document); + } + }; + // Make a reconciler + MonoReconciler m2 = new MonoReconciler(strategy, true); + m2.setIsIncrementalReconciler(true); + m2.setProgressMonitor(new NullProgressMonitor()); + m2.setDelay(500); + // Done + return m2; + } + + @SuppressWarnings("unused") + @Override + public ITextHover getTextHover(ISourceViewer sourceViewer, + String contentType) { + if (true) return super.getTextHover(sourceViewer, contentType); + // Add hover support for images + return new MDTextHover(); + } +} + +