Java Code Examples for com.intellij.openapi.editor.ScrollingModel#scrollVertically()

The following examples show how to use com.intellij.openapi.editor.ScrollingModel#scrollVertically() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyncScrollSupport.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void doScrollVertically(@Nonnull ScrollingModel model, int offset) {
  model.disableAnimation();
  try {
    model.scrollVertically(offset);
  }
  finally {
    model.enableAnimation();
  }
}
 
Example 2
Source File: SyncScrollSupport.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void doScrollVertically(@Nonnull Editor editor, int offset, boolean animated) {
  ScrollingModel model = editor.getScrollingModel();
  if (!animated) model.disableAnimation();
  model.scrollVertically(offset);
  if (!animated) model.enableAnimation();
}
 
Example 3
Source File: DesktopEditorWindow.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Tries to setup caret and viewport for the given editor from the selected one.
 *
 * @param toSync editor to setup caret and viewport for
 */
private void syncCaretIfPossible(@Nullable FileEditor[] toSync) {
  if (toSync == null) {
    return;
  }

  final DesktopEditorWithProviderComposite from = getSelectedEditor();
  if (from == null) {
    return;
  }

  final FileEditor caretSource = from.getSelectedEditor();
  if (!(caretSource instanceof TextEditor)) {
    return;
  }

  final Editor editorFrom = ((TextEditor)caretSource).getEditor();
  final int offset = editorFrom.getCaretModel().getOffset();
  if (offset <= 0) {
    return;
  }

  final int scrollOffset = editorFrom.getScrollingModel().getVerticalScrollOffset();

  for (FileEditor fileEditor : toSync) {
    if (!(fileEditor instanceof TextEditor)) {
      continue;
    }
    final Editor editor = ((TextEditor)fileEditor).getEditor();
    if (editorFrom.getDocument() == editor.getDocument()) {
      editor.getCaretModel().moveToOffset(offset);
      final ScrollingModel scrollingModel = editor.getScrollingModel();
      scrollingModel.scrollVertically(scrollOffset);

      SwingUtilities.invokeLater(() -> {
        if (!editor.isDisposed()) {
          scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
        }
      });
    }
  }
}