public static IXtextDocument get(Object ctx) { if (ctx instanceof IXtextDocument) return (IXtextDocument) ctx; if (ctx instanceof ProjectionDocument) return get(((ProjectionDocument) ctx).getMasterDocument()); if (ctx instanceof ITextViewer) return get(((ITextViewer) ctx).getDocument()); if (ctx instanceof XtextEditor) return ((XtextEditor) ctx).getDocument(); if (ctx instanceof IFile) { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); return get(activePage.findEditor(new FileEditorInput((IFile) ctx))); } return null; }
/** * Overwritten to handle offset properly. */ @Override protected boolean updateSlaveDocument(IDocument slaveDocument, int modelRangeOffset, int modelRangeLength) throws BadLocationException { if (slaveDocument instanceof ProjectionDocument) { ProjectionDocument projection = (ProjectionDocument) slaveDocument; int offset = modelRangeOffset; int length = modelRangeLength; if (!isProjectionMode()) { // mimic original TextViewer behavior IDocument master = projection.getMasterDocument(); int line = master.getLineOfOffset(modelRangeOffset); offset += master.getLineOffset(line); length = (modelRangeOffset - offset) + modelRangeLength; } try { // fHandleProjectionChanges= false; setPrivateHandleProjectionChangesField(false); projection.replaceMasterDocumentRanges(offset, length); } finally { // fHandleProjectionChanges= true; setPrivateHandleProjectionChangesField(true); } return true; } return false; }