从比较编辑器获取文档
如何从比较编辑器获取文档?我有 CompareViewerSwitchingPane,但我不知道如何提取左窗格和右窗格的文档。
我需要它来获取编辑器中显示的文本。
How to get document from compare editor? I have got CompareViewerSwitchingPane, but I don't know how to extract document for left and right pane.
I need it to get text that is displayed in the editor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面的代码示例展示了如何获取左右比较编辑器文档(以及文档中的文本):
The following code example shows how to get the left and right compare editor Document (and the text in the document):
我找到了一种方法来获取其 CompareEditorInput 的文档。有不同类型的比较输入:一种进入 CompareEditor,一种进入 CompareEditor 查看器。
我与 CompareUI.getDocument(Object) 非常接近,但第一次发现它时,我给了它 CompareEditorInput,它返回了我
null
而不是一个合理的对象(对于中级开发人员来说可能没有什么神秘之处,但不适合我)。我就搁置了,认为这个方法行不通。感谢 aphex,因此我对
CompareUI.getDocument(Object)
给予了更多关注它让我想到了一个想法:嘿,为什么不尝试传递 DiffNode 而不是 CompareEditor,最后它成功了!I have found a way how one could get document for his CompareEditorInput. There are different kinds of compare inputs: the one that goes to CompareEditor and the ones that go to CompareEditor viewers.
I was so close with CompareUI.getDocument(Object), but first time I found it I gave it CompareEditorInput and it returned me
null
instead of a reasonable object (may be for intermediate developer there is no mysteries, but not for me). And I put it aside thinking that this method does not work.Thanks to aphex due to which I gave a bit more attention to
CompareUI.getDocument(Object)
and it stroke me with an idea: hey, why not to try to pass DiffNode instead of a CompareEditor and finally it worked!您需要检索 EditorInput,它扩展了 CompareEditorInput。从 Pluginclass 中,您可以使用以下方法检索当前活动编辑器:
此处 您可以看到比较编辑器的工作原理以及如何向比较编辑器填充工作所需的信息。
编辑:链接已修复。
You need to retrieve the EditorInput, which extends CompareEditorInput. From the Pluginclass you can retrieve the current active editor using:
Here you can see how the compare editor works and how you fill the compare editor with the needed information to work.
EDIT: Link fixed.