上記をプログラム的に実行したいと思います。Eclipse TextEditor でカーソル位置を取得する方法とEclipse プラグインで現在のテキスト エディターのコルサー位置を取得する方法を調べた
ので、現在開いているエディターからカーソル オフセットを取得する方法がわかりました。ただし、プログラムで開いた新しいエディターでカーソルオフセットを設定しようとしています。
現在、新しいエディターを開く方法は次のとおりです。
IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
if (page != null) {
IEditorPart editor = page.getActiveEditor();
if (editor != null) {
IEditorInput input = editor.getEditorInput();
if (input instanceof IFileEditorInput) {
String fileLocation = ((IFileEditorInput) input).getFile().getLocation().toOSString();
String newFileLocartion = generateNewFileLocation(fileLocation);
File file = new File(newFileLocartion);
IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI());
try {
IDE.openEditorOnFileStore(page, fileStore);
} catch (PartInitException e) {
// TODO error handling
}
}
}
}
新しいエディターを特定のオフセットで開くように設定する方法はありますか (事前にオフセットを知っていると仮定します)。
ありがとう!