이클립스 플러그인 개발할때,
보통은 textEditor.selectAndReveal(offset, length)로 위치를 이동하는데,
lineNumber로 계산해서 호출할 수 있다.
보통은 textEditor.selectAndReveal(offset, length)로 위치를 이동하는데,
lineNumber로 계산해서 호출할 수 있다.
private void selectLine(ITextEditor textEditor, int lineNumber)
throws CoreException, BadLocationException {
if (lineNumber > 0) {
IEditorInput input = textEditor.getEditorInput();
int offset = 0;
int length = 0;
IDocumentProvider provider = textEditor.getDocumentProvider();
try {
provider.connect(input);
IDocument document = provider.getDocument(input);
IRegion region = document.getLineInformation(lineNumber - 1);
offset = region.getOffset();
length = region.getLength();
} finally {
provider.disconnect(input);
}
if (offset >= 0 && length >= 0) {
textEditor.selectAndReveal(offset, length);
}
}
}