Search in sources :

Example 6 with ScrollingModel

use of com.intellij.openapi.editor.ScrollingModel in project intellij-community by JetBrains.

the class RemoveMiddlemanHandler method invoke.

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"), REFACTORING_NAME, getHelpID());
        return;
    }
    invoke((PsiField) element, editor);
}
Also used : ScrollingModel(com.intellij.openapi.editor.ScrollingModel) PsiField(com.intellij.psi.PsiField) PsiElement(com.intellij.psi.PsiElement)

Example 7 with ScrollingModel

use of com.intellij.openapi.editor.ScrollingModel in project intellij-community by JetBrains.

the class SyncScrollSupport method scrollEditor.

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();
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) ScrollingModel(com.intellij.openapi.editor.ScrollingModel)

Example 8 with ScrollingModel

use of com.intellij.openapi.editor.ScrollingModel in project intellij-community by JetBrains.

the class CaretVisualPositionKeeper method restoreOriginalLocation.

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();
    }
}
Also used : ScrollingModel(com.intellij.openapi.editor.ScrollingModel) Editor(com.intellij.openapi.editor.Editor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with ScrollingModel

use of com.intellij.openapi.editor.ScrollingModel in project intellij-community by JetBrains.

the class DiffPanelImpl method onContentChangedIn.

public void onContentChangedIn(EditorSource source) {
    myDiffUpdater.contentRemoved(source);
    final EditorEx editor = source.getEditor();
    if (myIsHorizontal && source.getSide() == FragmentSide.SIDE1 && editor != null) {
        editor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT);
    }
    DiffSideView viewSide = getSideView(source.getSide());
    viewSide.setEditorSource(getProject(), source);
    Disposer.dispose(myScrollSupport);
    if (editor == null) {
        if (!myDisposed) {
            rediff();
        }
        return;
    }
    final MouseListener mouseListener = PopupHandler.installUnknownPopupHandler(editor.getContentComponent(), new MergeActionGroup(this, source.getSide()), ActionManager.getInstance());
    myDiffUpdater.contentAdded(source);
    editor.getSettings().setLineNumbersShown(true);
    editor.getSettings().setFoldingOutlineShown(false);
    editor.getFoldingModel().setFoldingEnabled(false);
    ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
    Editor editor1 = getEditor(FragmentSide.SIDE1);
    Editor editor2 = getEditor(FragmentSide.SIDE2);
    if (editor1 != null && editor2 != null && myIsSyncScroll) {
        myScrollSupport.install(new EditingSides[] { this });
    }
    final VisibleAreaListener visibleAreaListener = mySplitter.getVisibleAreaListener();
    final ScrollingModel scrollingModel = editor.getScrollingModel();
    if (visibleAreaListener != null) {
        scrollingModel.addVisibleAreaListener(visibleAreaListener);
        scrollingModel.addVisibleAreaListener(myVisibleAreaListener);
    }
    myFontSizeSynchronizer.synchronize(editor);
    source.addDisposable(new Disposable() {

        public void dispose() {
            myFontSizeSynchronizer.stopSynchronize(editor);
        }
    });
    source.addDisposable(new Disposable() {

        public void dispose() {
            if (visibleAreaListener != null) {
                scrollingModel.removeVisibleAreaListener(visibleAreaListener);
                scrollingModel.removeVisibleAreaListener(myVisibleAreaListener);
            }
            editor.getContentComponent().removeMouseListener(mouseListener);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorEx(com.intellij.openapi.editor.ex.EditorEx) MouseListener(java.awt.event.MouseListener) ScrollingModel(com.intellij.openapi.editor.ScrollingModel) VisibleAreaListener(com.intellij.openapi.editor.event.VisibleAreaListener) Editor(com.intellij.openapi.editor.Editor) EditorMarkupModel(com.intellij.openapi.editor.ex.EditorMarkupModel) MergeActionGroup(com.intellij.openapi.diff.actions.MergeActionGroup)

Example 10 with ScrollingModel

use of com.intellij.openapi.editor.ScrollingModel in project intellij-community by JetBrains.

the class SyncScrollSupport method doScrollVertically.

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();
}
Also used : ScrollingModel(com.intellij.openapi.editor.ScrollingModel)

Aggregations

ScrollingModel (com.intellij.openapi.editor.ScrollingModel)10 Editor (com.intellij.openapi.editor.Editor)3 CaretModel (com.intellij.openapi.editor.CaretModel)2 Disposable (com.intellij.openapi.Disposable)1 MergeActionGroup (com.intellij.openapi.diff.actions.MergeActionGroup)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 VisibleAreaListener (com.intellij.openapi.editor.event.VisibleAreaListener)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 EditorMarkupModel (com.intellij.openapi.editor.ex.EditorMarkupModel)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 PsiElement (com.intellij.psi.PsiElement)1 PsiField (com.intellij.psi.PsiField)1 MouseListener (java.awt.event.MouseListener)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1