Java 类com.intellij.openapi.editor.ScrollingModel 实例源码

项目:intellij-ce-playground    文件:TextStartAction.java   
@Override
public void execute(Editor editor, DataContext dataContext) {
  editor.getCaretModel().removeSecondaryCarets();
  editor.getCaretModel().moveToOffset(0);
  editor.getSelectionModel().removeSelection();

  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.RELATIVE);
  scrollingModel.enableAnimation();

  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project != null) {
    IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
    if (instance != null) {
      instance.includeCurrentCommandAsNavigation();
    }
  }
}
项目:intellij-ce-playground    文件:TextEndAction.java   
@Override
public void execute(Editor editor, DataContext dataContext) {
  editor.getCaretModel().removeSecondaryCarets();
  int offset = editor.getDocument().getTextLength();
  if (editor instanceof EditorImpl && ((EditorImpl)editor).myUseNewRendering) {
    editor.getCaretModel().moveToLogicalPosition(editor.offsetToLogicalPosition(offset).leanForward(true));
  }
  else {
    editor.getCaretModel().moveToOffset(offset);
  }
  editor.getSelectionModel().removeSelection();

  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.CENTER);
  scrollingModel.enableAnimation();

  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project != null) {
    IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
    if (instance != null) {
      instance.includeCurrentCommandAsNavigation();
    }
  }
}
项目:tools-idea    文件:TextStartAction.java   
@Override
public void execute(Editor editor, DataContext dataContext) {
  editor.getCaretModel().moveToOffset(0);
  editor.getSelectionModel().removeSelection();

  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.RELATIVE);
  scrollingModel.enableAnimation();

  Project project = PlatformDataKeys.PROJECT.getData(dataContext);
  if (project != null) {
    IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
    if (instance != null) {
      instance.includeCurrentCommandAsNavigation();
    }
  }
}
项目:tools-idea    文件:TextEndAction.java   
@Override
public void execute(Editor editor, DataContext dataContext) {
  int offset = editor.getDocument().getTextLength();
  editor.getCaretModel().moveToOffset(offset);
  editor.getSelectionModel().removeSelection();

  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.CENTER);
  scrollingModel.enableAnimation();

  Project project = PlatformDataKeys.PROJECT.getData(dataContext);
  if (project != null) {
    IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
    if (instance != null) {
      instance.includeCurrentCommandAsNavigation();
    }
  }
}
项目:intellij-idea-plugin    文件:IDEUtil.java   
private static void openSingleSelection(Project project, Object selection, Optional<UIRegion<Object>> region)
{
   if (selection instanceof FileResource)
   {
      FileResource<?> resource = (FileResource<?>) selection;
      File file = resource.getUnderlyingResourceObject();
      openFile(project, file);
      region.ifPresent(r ->
      {
         Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
         if (editor == null)
         {
            return;
         }
         SelectionModel selectionModel = editor.getSelectionModel();
         ScrollingModel scrollingModel = editor.getScrollingModel();

         LogicalPosition from = new LogicalPosition(r.getStartLine() - 1, r.getStartPosition());
         LogicalPosition to = new LogicalPosition(r.getEndLine() - 1, r.getEndPosition(), true);

         selectionModel.setBlockSelection(from, to);
         scrollingModel.scrollTo(from, ScrollType.CENTER);
      });
   }
}
项目:consulo    文件:TextStartAction.java   
@Override
public void execute(Editor editor, DataContext dataContext) {
  editor.getCaretModel().removeSecondaryCarets();
  editor.getCaretModel().moveToOffset(0);
  editor.getSelectionModel().removeSelection();

  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.RELATIVE);
  scrollingModel.enableAnimation();

  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project != null) {
    IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
    if (instance != null) {
      instance.includeCurrentCommandAsNavigation();
    }
  }
}
项目:consulo    文件:TextEndAction.java   
@Override
public void execute(Editor editor, DataContext dataContext) {
  editor.getCaretModel().removeSecondaryCarets();
  int offset = editor.getDocument().getTextLength();
  if (editor instanceof EditorImpl) {
    editor.getCaretModel().moveToLogicalPosition(editor.offsetToLogicalPosition(offset).leanForward(true));
  }
  else {
    editor.getCaretModel().moveToOffset(offset);
  }
  editor.getSelectionModel().removeSelection();

  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.CENTER);
  scrollingModel.enableAnimation();

  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project != null) {
    IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
    if (instance != null) {
      instance.includeCurrentCommandAsNavigation();
    }
  }
}
项目:intellij-ce-playground    文件:WrapReturnValueHandler.java   
public void invoke(@NotNull Project project,
                   Editor editor,
                   PsiFile file,
                   DataContext dataContext){
    final ScrollingModel scrollingModel = editor.getScrollingModel();
    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    PsiMethod selectedMethod = null;
    if(element instanceof PsiMethod){
        selectedMethod = (PsiMethod) element;
    } else{
        final CaretModel caretModel = editor.getCaretModel();
        final int position = caretModel.getOffset();
        PsiElement selectedElement = file.findElementAt(position);
        while(selectedElement != null){
            if(selectedElement instanceof PsiMethod){
                selectedMethod = (PsiMethod) selectedElement;
                break;
            }
            selectedElement = selectedElement.getParent();
        }
    }
    if(selectedMethod == null){
      CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message(
          "the.caret.should.be.positioned.at.the.name.of.the.method.to.be.refactored"), null, this.getHelpID());
      return;
    }
  invoke(project, selectedMethod, editor);
}
项目:intellij-ce-playground    文件:IntroduceParameterObjectHandler.java   
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  final ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
  PsiMethod selectedMethod = getSelectedMethod(editor, file, dataContext);
  if (selectedMethod == null) {
    final String message = RefactorJBundle.message("cannot.perform.the.refactoring") +
                           RefactorJBundle.message("the.caret.should.be.positioned.at.the.name.of.the.method.to.be.refactored");
    CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.IntroduceParameterObject);
    return;
  }
  invoke(project, selectedMethod, editor);
}
项目:intellij-ce-playground    文件:RemoveMiddlemanHandler.java   
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  final ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
  final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
  if (!(element instanceof PsiField)) {
    CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message(
        "the.caret.should.be.positioned.at.the.name.of.the.field.to.be.refactored"), null, getHelpID());
    return;
  }
  invoke((PsiField)element, editor);
}
项目:intellij-ce-playground    文件:ExtractClassHandler.java   
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  final ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
  final CaretModel caretModel = editor.getCaretModel();
  final int position = caretModel.getOffset();
  final PsiElement element = file.findElementAt(position);

  final PsiMember selectedMember = PsiTreeUtil.getParentOfType(element, PsiMember.class, true);
  if (selectedMember == null) {
    //todo
    return;
  }

  PsiClass containingClass = selectedMember.getContainingClass();

  if (containingClass == null && selectedMember instanceof PsiClass) {
    containingClass = (PsiClass)selectedMember;
  }

  final String cannotRefactorMessage = getCannotRefactorMessage(containingClass);
  if (cannotRefactorMessage != null)  {
    CommonRefactoringUtil.showErrorHint(project, editor, 
                                        RefactorJBundle.message("cannot.perform.the.refactoring") + cannotRefactorMessage, 
                                        null, getHelpID());
    return;
  }
  new ExtractClassDialog(containingClass, selectedMember).show();
}
项目:intellij-ce-playground    文件:SyncScrollSupport.java   
private static void doScrollVertically(@NotNull ScrollingModel model, int offset) {
  model.disableAnimation();
  try {
    model.scrollVertically(offset);
  }
  finally {
    model.enableAnimation();
  }
}
项目:intellij-ce-playground    文件:SyncScrollSupport.java   
private static void doScrollHorizontally(@NotNull ScrollingModel model, int offset) {
  model.disableAnimation();
  try {
    model.scrollHorizontally(offset);
  }
  finally {
    model.enableAnimation();
  }
}
项目:intellij-ce-playground    文件:SyncScrollSupport.java   
public static void scrollEditor(@NotNull Editor editor, int logicalLine) {
  editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(logicalLine, 0));
  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.CENTER);
  scrollingModel.enableAnimation();
}
项目:intellij-ce-playground    文件:GotoNextErrorHandler.java   
static void navigateToError(Project project, final Editor editor, HighlightInfo info) {
  int oldOffset = editor.getCaretModel().getOffset();

  final int offset = getNavigationPositionFor(info, editor.getDocument());
  final int endOffset = info.getActualEndOffset();

  final ScrollingModel scrollingModel = editor.getScrollingModel();
  if (offset != oldOffset) {
    ScrollType scrollType = offset > oldOffset ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
    editor.getSelectionModel().removeSelection();
    editor.getCaretModel().removeSecondaryCarets();
    editor.getCaretModel().moveToOffset(offset);
    scrollingModel.scrollToCaret(scrollType);
  }

  scrollingModel.runActionOnScrollingFinished(
    new Runnable(){
      @Override
      public void run() {
        int maxOffset = editor.getDocument().getTextLength() - 1;
        if (maxOffset == -1) return;
        scrollingModel.scrollTo(editor.offsetToLogicalPosition(Math.min(maxOffset, endOffset)), ScrollType.MAKE_VISIBLE);
        scrollingModel.scrollTo(editor.offsetToLogicalPosition(Math.min(maxOffset, offset)), ScrollType.MAKE_VISIBLE);
      }
    }
  );

  IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLToggleVariablesAction.java   
@Override
public void setSelected(AnActionEvent e, boolean state) {

    final Editor variablesEditor = getVariablesEditor(e);
    if (variablesEditor != null) {

        final Editor queryEditor = variablesEditor.getUserData(JSGraphQLLanguageUIProjectService.GRAPH_QL_QUERY_EDITOR);
        if(queryEditor == null) {
            // not linked to a query editor
            return;
        }

        final ScrollingModel scroll = queryEditor.getScrollingModel();
        final int currentScroll = scroll.getVerticalScrollOffset();

        variablesEditor.putUserData(JS_GRAPH_QL_VARIABLES_MODEL, state ? Boolean.TRUE : Boolean.FALSE);
        variablesEditor.getComponent().setVisible(state);

        if (state) {
            variablesEditor.getContentComponent().grabFocus();
        } else {
            ApplicationManager.getApplication().runWriteAction(() -> {
                variablesEditor.getDocument().setText("");
            });
            queryEditor.getContentComponent().grabFocus();
        }

        // restore scroll position after the editor has had a chance to re-layout
        ApplicationManager.getApplication().invokeLater(() -> {
            UIUtil.invokeLaterIfNeeded(() -> scroll.scrollVertically(currentScroll));
        });

    }

}
项目:intellij-joined-tab-scrolling    文件:JoinedScroller.java   
EditorTopBottom(Editor editor) {
  this.editor = editor;
  ScrollingModel scrolling = editor.getScrollingModel();
  verticalScrollOffset = scrolling.getVerticalScrollOffset();
  // convert to visual position (including folding) if this is logical (ignoring folding).
  VisualPosition vp = editor.xyToVisualPosition(
      new Point(scrolling.getVisibleArea().x, verticalScrollOffset));
  topLine = vp.line;
  column = vp.column;
  bottomLine = editor.xyToVisualPosition(
      new Point(scrolling.getVisibleArea().x,
          verticalScrollOffset + scrolling.getVisibleArea().height)).line;
  linesVisible = bottomLine - topLine + 1; // inclusive of both lines, so add one.
  Preconditions.checkState(linesVisible >= 0, "Invalid lines visible calculation - bug!");
}
项目:intellij-joined-tab-scrolling    文件:JoinedScroller.java   
private static void doScrollVertically(@NotNull ScrollingModel model, int offset) {
  model.disableAnimation();
  try {
    model.scrollVertically(offset);
  } finally {
    model.enableAnimation();
  }
}
项目:power-mode-intellij-plugin    文件:ParticleContainerManager.java   
private void updateInUI(Editor editor) {
    VisualPosition visualPosition = editor.getCaretModel().getVisualPosition();
    Point point = editor.visualPositionToXY(visualPosition);
    ScrollingModel scrollingModel = editor.getScrollingModel();
    point.x = point.x - scrollingModel.getHorizontalScrollOffset();
    point.y = point.y - scrollingModel.getVerticalScrollOffset();
    final ParticleContainer particleContainer = particleContainers.get(editor);
    if (particleContainer != null) {
        particleContainer.update(point);
    }
}
项目:tools-idea    文件:WrapReturnValueHandler.java   
public void invoke(@NotNull Project project,
                   Editor editor,
                   PsiFile file,
                   DataContext dataContext){
    final ScrollingModel scrollingModel = editor.getScrollingModel();
    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
    final PsiElement element = LangDataKeys.PSI_ELEMENT.getData(dataContext);
    PsiMethod selectedMethod = null;
    if(element instanceof PsiMethod){
        selectedMethod = (PsiMethod) element;
    } else{
        final CaretModel caretModel = editor.getCaretModel();
        final int position = caretModel.getOffset();
        PsiElement selectedElement = file.findElementAt(position);
        while(selectedElement != null){
            if(selectedElement instanceof PsiMethod){
                selectedMethod = (PsiMethod) selectedElement;
                break;
            }
            selectedElement = selectedElement.getParent();
        }
    }
    if(selectedMethod == null){
      CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message(
          "the.caret.should.be.positioned.at.the.name.of.the.method.to.be.refactored"), null, this.getHelpID());
      return;
    }
  invoke(project, selectedMethod, editor);
}
项目:tools-idea    文件:IntroduceParameterObjectHandler.java   
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  final ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
  final PsiElement element = LangDataKeys.PSI_ELEMENT.getData(dataContext);
  PsiMethod selectedMethod = null;
  if (element instanceof PsiMethod) {
    selectedMethod = (PsiMethod)element;
  }
  else if (element instanceof PsiParameter && ((PsiParameter)element).getDeclarationScope() instanceof PsiMethod){
    selectedMethod = (PsiMethod)((PsiParameter)element).getDeclarationScope();
  }
  else {
    final CaretModel caretModel = editor.getCaretModel();
    final int position = caretModel.getOffset();
    final PsiElement elementAt = file.findElementAt(position);
    final PsiMethodCallExpression methodCallExpression =
     PsiTreeUtil.getParentOfType(elementAt, PsiMethodCallExpression.class);
    if (methodCallExpression != null) {
      selectedMethod = methodCallExpression.resolveMethod();
    } else {
      final PsiParameterList parameterList = PsiTreeUtil.getParentOfType(elementAt, PsiParameterList.class);
      if (parameterList != null && parameterList.getParent() instanceof PsiMethod) {
        selectedMethod = (PsiMethod)parameterList.getParent();
      }
    }
  }
  if (selectedMethod == null) {
    final String message = RefactorJBundle.message("cannot.perform.the.refactoring") +
                           RefactorJBundle.message("the.caret.should.be.positioned.at.the.name.of.the.method.to.be.refactored");
    CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.IntroduceParameterObject);
    return;
  }
  invoke(project, selectedMethod, editor);
}
项目:tools-idea    文件:RemoveMiddlemanHandler.java   
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  final ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
  final PsiElement element = LangDataKeys.PSI_ELEMENT.getData(dataContext);
  if (!(element instanceof PsiField)) {
    CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message(
        "the.caret.should.be.positioned.at.the.name.of.the.field.to.be.refactored"), null, getHelpID());
    return;
  }
  invoke((PsiField)element, editor);
}
项目:tools-idea    文件:SyncScrollSupport.java   
private static void syncHorizontalScroll(Pair<FragmentSide,EditingSides> context, Rectangle newRectangle, Rectangle oldRectangle) {
  int newScrollOffset = newRectangle.x;
  if (newScrollOffset == oldRectangle.x) return;
  EditingSides sidesContainer = context.getSecond();
  FragmentSide masterSide = context.getFirst();
  Editor slaveEditor = sidesContainer.getEditor(masterSide.otherSide());
  if (slaveEditor == null) return;

  ScrollingModel scrollingModel = slaveEditor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollHorizontally(newScrollOffset);
  scrollingModel.enableAnimation();
}
项目:tools-idea    文件:SyncScrollSupport.java   
public static void scrollEditor(Editor editor, int logicalLine) {
  editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(logicalLine, 0));
  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.CENTER);
  scrollingModel.enableAnimation();
}
项目:tools-idea    文件:TextEndWithSelectionAction.java   
@Override
public void execute(Editor editor, DataContext dataContext) {
  int selectionStart = editor.getSelectionModel().getLeadSelectionOffset();
  int offset = editor.getDocument().getTextLength();
  editor.getCaretModel().moveToOffset(offset);
  editor.getSelectionModel().setSelection(selectionStart, offset);

  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.CENTER);
  scrollingModel.enableAnimation();
}
项目:tools-idea    文件:TextStartWithSelectionAction.java   
@Override
public void execute(Editor editor, DataContext dataContext) {
  int selectionStart = editor.getSelectionModel().getLeadSelectionOffset();
  editor.getCaretModel().moveToOffset(0);
  editor.getSelectionModel().setSelection(selectionStart, 0);

  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.RELATIVE);
  scrollingModel.enableAnimation();
}
项目:tools-idea    文件:ChangesFragmentedDiffPanel.java   
private MyScrollingHelper() {
  myLeftScroll = new JScrollBar(JScrollBar.HORIZONTAL);
  myLeftScroll.setUI(ButtonlessScrollBarUI.createNormal());

  myLeftEditors = new ArrayList<Editor>();
  myRightEditors = new ArrayList<Editor>();

  myMaxColumnsLeft = 0;
  myMaxColumnsRight = 0;
  myLeftModels = new ArrayList<ScrollingModel>();
  myRightModels = new ArrayList<ScrollingModel>();
}
项目:tools-idea    文件:ChangesFragmentedDiffPanel.java   
private void scrollOther(int scrollPosCorrected, final int maxColumnsOur, int maxColumnsOther, final List<ScrollingModel> models) {
  int pos2;
  if (myLeftScroll.getValue() == 0) {
    pos2 = 0;
  } else if ((scrollPosCorrected + myLeftScroll.getModel().getExtent()) >= maxColumnsOur) {
    pos2 = maxColumnsOther + 1;
  } else {
    pos2 = (int) (scrollPosCorrected * (((double) maxColumnsOther)/ maxColumnsOur));
  }
  final int pointX2 = (int)myEditor.logicalPositionToXY(new LogicalPosition(0, pos2)).getX();
  for (ScrollingModel model : models) {
    model.scrollHorizontally(pointX2);
  }
}
项目:tools-idea    文件:GotoNextErrorHandler.java   
static void navigateToError(Project project, final Editor editor, HighlightInfo info) {
  int oldOffset = editor.getCaretModel().getOffset();

  final int offset = getNavigationPositionFor(info, editor.getDocument());
  final int endOffset = info.getActualEndOffset();

  final ScrollingModel scrollingModel = editor.getScrollingModel();
  if (offset != oldOffset) {
    ScrollType scrollType = offset > oldOffset ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
    editor.getSelectionModel().removeSelection();
    editor.getCaretModel().moveToOffset(offset);
    scrollingModel.scrollToCaret(scrollType);
  }

  scrollingModel.runActionOnScrollingFinished(
    new Runnable(){
      @Override
      public void run() {
        int maxOffset = editor.getDocument().getTextLength() - 1;
        if (maxOffset == -1) return;
        scrollingModel.scrollTo(editor.offsetToLogicalPosition(Math.min(maxOffset, endOffset)), ScrollType.MAKE_VISIBLE);
        scrollingModel.scrollTo(editor.offsetToLogicalPosition(Math.min(maxOffset, offset)), ScrollType.MAKE_VISIBLE);
      }
    }
  );

  IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
}
项目:intellij-plugin-v4    文件:MyActionUtils.java   
public static void moveCursor(Editor editor, int cursorOffset) {
    CaretModel caretModel = editor.getCaretModel();
    caretModel.moveToOffset(cursorOffset);
    ScrollingModel scrollingModel = editor.getScrollingModel();
    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
    editor.getContentComponent().requestFocus();
}
项目:intellij-plugin-v4    文件:InputPanel.java   
public void jumpToGrammarPosition(Project project, int start) {
    final ANTLRv4PluginController controller = ANTLRv4PluginController.getInstance(project);
    if ( controller==null ) return;
    final Editor grammarEditor = controller.getEditor(previewState.grammarFile);
    if ( grammarEditor==null ) return;

    CaretModel caretModel = grammarEditor.getCaretModel();
    caretModel.moveToOffset(start);
    ScrollingModel scrollingModel = grammarEditor.getScrollingModel();
    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
    grammarEditor.getContentComponent().requestFocus();
}
项目:consulo    文件:SyncScrollSupport.java   
private static void doScrollVertically(@Nonnull ScrollingModel model, int offset) {
  model.disableAnimation();
  try {
    model.scrollVertically(offset);
  }
  finally {
    model.enableAnimation();
  }
}
项目:consulo    文件:SyncScrollSupport.java   
private static void doScrollHorizontally(@Nonnull ScrollingModel model, int offset) {
  model.disableAnimation();
  try {
    model.scrollHorizontally(offset);
  }
  finally {
    model.enableAnimation();
  }
}
项目:consulo    文件:SyncScrollSupport.java   
public static void scrollEditor(@Nonnull Editor editor, int logicalLine) {
  editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(logicalLine, 0));
  ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.disableAnimation();
  scrollingModel.scrollToCaret(ScrollType.CENTER);
  scrollingModel.enableAnimation();
}
项目:consulo    文件:CaretVisualPositionKeeper.java   
public void restoreOriginalLocation() {
  for (Map.Entry<Editor, Integer> e : myCaretRelativeVerticalPositions.entrySet()) {
    Editor editor = e.getKey();
    int relativePosition = e.getValue();
    Point caretLocation = editor.visualPositionToXY(editor.getCaretModel().getVisualPosition());
    int scrollOffset = caretLocation.y - relativePosition;
    ScrollingModel scrollingModel = editor.getScrollingModel();
    Rectangle targetArea = scrollingModel.getVisibleAreaOnScrollingFinished();
    // when animated scrolling is in progress, we'll not stop it immediately
    boolean useAnimation = !targetArea.equals(scrollingModel.getVisibleArea());
    if (!useAnimation) scrollingModel.disableAnimation();
    scrollingModel.scroll(targetArea.x, scrollOffset);
    if (!useAnimation) scrollingModel.enableAnimation();
  }
}
项目:consulo    文件:GotoNextErrorHandler.java   
static void navigateToError(Project project, final Editor editor, HighlightInfo info) {
  int oldOffset = editor.getCaretModel().getOffset();

  final int offset = getNavigationPositionFor(info, editor.getDocument());
  final int endOffset = info.getActualEndOffset();

  final ScrollingModel scrollingModel = editor.getScrollingModel();
  if (offset != oldOffset) {
    ScrollType scrollType = offset > oldOffset ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
    editor.getSelectionModel().removeSelection();
    editor.getCaretModel().removeSecondaryCarets();
    editor.getCaretModel().moveToOffset(offset);
    scrollingModel.scrollToCaret(scrollType);
  }

  scrollingModel.runActionOnScrollingFinished(
          new Runnable(){
            @Override
            public void run() {
              int maxOffset = editor.getDocument().getTextLength() - 1;
              if (maxOffset == -1) return;
              scrollingModel.scrollTo(editor.offsetToLogicalPosition(Math.min(maxOffset, endOffset)), ScrollType.MAKE_VISIBLE);
              scrollingModel.scrollTo(editor.offsetToLogicalPosition(Math.min(maxOffset, offset)), ScrollType.MAKE_VISIBLE);
            }
          }
  );

  IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
}
项目:consulo-java    文件:WrapReturnValueHandler.java   
public void invoke(@NotNull Project project,
                   Editor editor,
                   PsiFile file,
                   DataContext dataContext){
    final ScrollingModel scrollingModel = editor.getScrollingModel();
    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
    final PsiElement element = dataContext.getData(LangDataKeys.PSI_ELEMENT);
    PsiMethod selectedMethod = null;
    if(element instanceof PsiMethod){
        selectedMethod = (PsiMethod) element;
    } else{
        final CaretModel caretModel = editor.getCaretModel();
        final int position = caretModel.getOffset();
        PsiElement selectedElement = file.findElementAt(position);
        while(selectedElement != null){
            if(selectedElement instanceof PsiMethod){
                selectedMethod = (PsiMethod) selectedElement;
                break;
            }
            selectedElement = selectedElement.getParent();
        }
    }
    if(selectedMethod == null){
      CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message(
          "the.caret.should.be.positioned.at.the.name.of.the.method.to.be.refactored"), null, this.getHelpID());
      return;
    }
  invoke(project, selectedMethod, editor);
}
项目:consulo-java    文件:IntroduceParameterObjectHandler.java   
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  final ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
  final PsiElement element = dataContext.getData(LangDataKeys.PSI_ELEMENT);
  PsiMethod selectedMethod = null;
  if (element instanceof PsiMethod) {
    selectedMethod = (PsiMethod)element;
  }
  else if (element instanceof PsiParameter && ((PsiParameter)element).getDeclarationScope() instanceof PsiMethod){
    selectedMethod = (PsiMethod)((PsiParameter)element).getDeclarationScope();
  }
  else {
    final CaretModel caretModel = editor.getCaretModel();
    final int position = caretModel.getOffset();
    final PsiElement elementAt = file.findElementAt(position);
    final PsiMethodCallExpression methodCallExpression =
     PsiTreeUtil.getParentOfType(elementAt, PsiMethodCallExpression.class);
    if (methodCallExpression != null) {
      selectedMethod = methodCallExpression.resolveMethod();
    } else {
      final PsiParameterList parameterList = PsiTreeUtil.getParentOfType(elementAt, PsiParameterList.class);
      if (parameterList != null && parameterList.getParent() instanceof PsiMethod) {
        selectedMethod = (PsiMethod)parameterList.getParent();
      }
    }
  }
  if (selectedMethod == null) {
    final String message = RefactorJBundle.message("cannot.perform.the.refactoring") +
                           RefactorJBundle.message("the.caret.should.be.positioned.at.the.name.of.the.method.to.be.refactored");
    CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.IntroduceParameterObject);
    return;
  }
  invoke(project, selectedMethod, editor);
}
项目:consulo-java    文件:RemoveMiddlemanHandler.java   
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  final ScrollingModel scrollingModel = editor.getScrollingModel();
  scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
  final PsiElement element = dataContext.getData(LangDataKeys.PSI_ELEMENT);
  if (!(element instanceof PsiField)) {
    CommonRefactoringUtil.showErrorHint(project, editor, RefactorJBundle.message("cannot.perform.the.refactoring") + RefactorJBundle.message(
        "the.caret.should.be.positioned.at.the.name.of.the.field.to.be.refactored"), null, getHelpID());
    return;
  }
  invoke((PsiField)element, editor);
}
项目:intellij-ce-playground    文件:SyncScrollSupport.java   
private static void doScrollVertically(@NotNull Editor editor, int offset, boolean animated) {
  ScrollingModel model = editor.getScrollingModel();
  if (!animated) model.disableAnimation();
  model.scrollVertically(offset);
  if (!animated) model.enableAnimation();
}