다음은 처리기 execute() 메소드의 코드입니다. 그것은 꽤 쉽게 명령 및 plugin.xml 파일을 통한 바인딩에 연결될 수 있습니다.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editorPart = HandlerUtil.getActiveEditorChecked(event);
ITextOperationTarget target = (ITextOperationTarget) editorPart
.getAdapter(ITextOperationTarget.class);
if (!(target instanceof ITextViewer)) return null;
ITextViewer textViewer = (ITextViewer) target;
int topIndex = textViewer.getTopIndex();
int bottomIndex = textViewer.getBottomIndex();
int middle = (topIndex + bottomIndex)/2;
IDocument doc = textViewer.getDocument();
try {
IRegion widgetLineInformation = doc.getLineInformation(middle);
int widgetOffset = widgetLineInformation.getOffset();
textViewer.getTextWidget().setSelection(widgetOffset);
} catch (BadLocationException e) {
return null;
}
return null;
}
Eclipse는 기본적으로이 작업을 수행 할 수 없습니다. 하지만 거기에 플러그인을 찾으려고 할 수 있습니다. 이를 달성하는 가장 가까운 방법은 Ctrl + L을 사용하여 대화 상자를 열고 점프하려는 행 번호를 입력하는 것입니다. –
아니, 그런 식으로 Eclipse에 아무것도 없다. 그러나 나는 (프로그래머를위한 툴을 개발할 때 내 생계를 꾸린 파워 유저와 누군가로서) 매우 흥미 롭습니다. 에디터 윈도우의 중심에 "지리적으로"있는 라인으로 뛰어들 때 당신이 정말로하고있는 것은 무엇입니까? ? 어쩌면 당신이 잃어버린 어떤 효율성이라도 되 찾을 수있는 Eclipse의 다른 기능이있을 수 있습니다. –
예를 들어 vim 편집기에서이 작업은 M 명령을 사용하여 수행됩니다. "화면 중앙 근처에서 보이는 것을 편집하고 싶다"는 것 이외의 근본적인 동기는 없습니다. 화면의 상단과 하단에 대해서도 비슷한 명령을 사용할 수 있습니다 (vim에서 각각 H와 L). –