如何从比较编辑器获取文档?我有CompareViewerSwitchingPane,但是我不知道如何为左右窗格提取文档。
我需要它来获取在编辑器中显示的文本。
最佳答案
下面的代码示例演示如何获取左右比较编辑器Document(以及文档中的文本):
IWorkbench workbench = PlatformUI.getWorkbench();
IEditorPart editorPart = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
CompareEditorInput compareEditorInput = (CompareEditorInput) editorPart.getEditorInput();
ICompareInput compareInput = (ICompareInput) compareEditorInput.getCompareResult();
ITypedElement leftTypedElement = compareInput.getLeft();
ITypedElement rightTypedElement = compareInput.getRight();
IDocument leftDocument = CompareUI.getDocument(leftTypedElement);
IDocument rightDocument = CompareUI.getDocument(rightTypedElement);
String left = leftDocument.get();
String right = rightDocument.get();