mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-79691 Option to keep cursor on screen when scrolling with Ctrl+Up/Down
This commit is contained in:
+32
-19
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,27 +55,38 @@ public class EditorActionUtil {
|
||||
private EditorActionUtil() {
|
||||
}
|
||||
|
||||
public static void scrollRelatively(Editor editor, int lineShift) {
|
||||
/**
|
||||
* Tries to change given editor's viewport position in vertical dimension by the given number of visual lines.
|
||||
*
|
||||
* @param editor target editor which viewport position should be changed
|
||||
* @param lineShift defines viewport position's change length
|
||||
* @param moveCaret flag that identifies whether caret should be moved if its current position becomes off-screen
|
||||
*/
|
||||
public static void scrollRelatively(Editor editor, int lineShift, boolean moveCaret) {
|
||||
if (lineShift != 0) {
|
||||
editor.getScrollingModel().scrollVertically(
|
||||
editor.getScrollingModel().getVerticalScrollOffset() + lineShift * editor.getLineHeight()
|
||||
);
|
||||
}
|
||||
|
||||
//Rectangle viewRectangle = editor.getScrollingModel().getVisibleArea();
|
||||
//int lineNumber = editor.getCaretModel().getVisualPosition().line;
|
||||
//if (viewRectangle != null) {
|
||||
// VisualPosition startPos = editor.xyToVisualPosition(new Point(0, viewRectangle.y));
|
||||
// int start = startPos.line + 1;
|
||||
// VisualPosition endPos = editor.xyToVisualPosition(new Point(0, viewRectangle.y + viewRectangle.height));
|
||||
// int end = endPos.line - 2;
|
||||
//if (lineNumber < start) {
|
||||
// editor.getCaretModel().moveCaretRelatively(0, start - lineNumber, false, false, true);
|
||||
//}
|
||||
//else if (lineNumber > end) {
|
||||
// editor.getCaretModel().moveCaretRelatively(0, end - lineNumber, false, false, true);
|
||||
//}
|
||||
//}
|
||||
if (!moveCaret) {
|
||||
return;
|
||||
}
|
||||
|
||||
Rectangle viewRectangle = editor.getScrollingModel().getVisibleArea();
|
||||
int lineNumber = editor.getCaretModel().getVisualPosition().line;
|
||||
if (viewRectangle != null) {
|
||||
VisualPosition startPos = editor.xyToVisualPosition(new Point(0, viewRectangle.y));
|
||||
int start = startPos.line + 1;
|
||||
VisualPosition endPos = editor.xyToVisualPosition(new Point(0, viewRectangle.y + viewRectangle.height));
|
||||
int end = endPos.line - 2;
|
||||
if (lineNumber < start) {
|
||||
editor.getCaretModel().moveCaretRelatively(0, start - lineNumber, false, false, true);
|
||||
}
|
||||
else if (lineNumber > end) {
|
||||
editor.getCaretModel().moveCaretRelatively(0, end - lineNumber, false, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void moveCaretRelativelyAndScroll(Editor editor,
|
||||
@@ -215,9 +226,11 @@ public class EditorActionUtil {
|
||||
}
|
||||
|
||||
if (isCamel) {
|
||||
if (firstIsIdentifierPart && secondIsIdentifierPart &&
|
||||
(Character.isLowerCase(prev) && Character.isUpperCase(current) || prev != '_' && current == '_' ||
|
||||
Character.isUpperCase(prev) && Character.isUpperCase(current) && Character.isLowerCase(next))) {
|
||||
if (firstIsIdentifierPart
|
||||
&& (Character.isLowerCase(prev) && Character.isUpperCase(current)
|
||||
|| prev != '_' && current == '_'
|
||||
|| Character.isUpperCase(prev) && Character.isUpperCase(current) && Character.isLowerCase(next)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,7 @@ public class ScrollDownAction extends InactiveEditorAction {
|
||||
private static class Handler extends EditorActionHandler {
|
||||
@Override
|
||||
public void execute(Editor editor, DataContext dataContext) {
|
||||
EditorActionUtil.scrollRelatively(editor, 1);
|
||||
EditorActionUtil.scrollRelatively(editor, 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.editor.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
|
||||
/**
|
||||
* Moves editor viewport one visual line down. Caret is also moved one line down if it becomes off-screen
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 1/13/12 1:22 PM
|
||||
*/
|
||||
public class ScrollDownAndMoveAction extends InactiveEditorAction {
|
||||
|
||||
public ScrollDownAndMoveAction() {
|
||||
super(new Handler());
|
||||
}
|
||||
|
||||
private static class Handler extends EditorActionHandler {
|
||||
@Override
|
||||
public void execute(Editor editor, DataContext dataContext) {
|
||||
EditorActionUtil.scrollRelatively(editor, 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,7 @@ public class ScrollUpAction extends InactiveEditorAction {
|
||||
private static class Handler extends EditorActionHandler {
|
||||
@Override
|
||||
public void execute(Editor editor, DataContext dataContext) {
|
||||
EditorActionUtil.scrollRelatively(editor, -1);
|
||||
EditorActionUtil.scrollRelatively(editor, -1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.editor.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
|
||||
/**
|
||||
* Moves editor viewport one visual line up. Caret is also moved one line up if it becomes off-screen.
|
||||
*
|
||||
* @author Denis Zhdanov
|
||||
* @since 1/13/12 1:21 PM
|
||||
*/
|
||||
public class ScrollUpAndMoveAction extends InactiveEditorAction {
|
||||
|
||||
public ScrollUpAndMoveAction() {
|
||||
super(new Handler());
|
||||
}
|
||||
|
||||
private static class Handler extends EditorActionHandler {
|
||||
@Override
|
||||
public void execute(Editor editor, DataContext dataContext) {
|
||||
EditorActionUtil.scrollRelatively(editor, -1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,8 @@ action.EditorTab.text=Tab
|
||||
action.EmacsStyleIndent.text=Emacs Tab
|
||||
action.EditorScrollUp.text=Scroll Up
|
||||
action.EditorScrollDown.text=Scroll Down
|
||||
action.EditorScrollUpAndMove.text=Scroll Up and Move if Necessary
|
||||
action.EditorScrollDownAndMove.text=Scroll Down and Move if Necessary
|
||||
action.EditorScrollTop.text=Scroll to Top
|
||||
action.EditorScrollBottom.text=Scroll to Bottom
|
||||
action.EditorMoveUpAndScroll.text=Move Up and Scroll
|
||||
|
||||
@@ -51,6 +51,8 @@
|
||||
<action id="EditorTab" class="com.intellij.openapi.editor.actions.TabAction"/>
|
||||
<action id="EditorScrollUp" class="com.intellij.openapi.editor.actions.ScrollUpAction"/>
|
||||
<action id="EditorScrollDown" class="com.intellij.openapi.editor.actions.ScrollDownAction"/>
|
||||
<action id="EditorScrollUpAndMove" class="com.intellij.openapi.editor.actions.ScrollUpAndMoveAction"/>
|
||||
<action id="EditorScrollDownAndMove" class="com.intellij.openapi.editor.actions.ScrollDownAndMoveAction"/>
|
||||
<action id="EditorScrollTop" class="com.intellij.openapi.editor.actions.ScrollToTopAction"/>
|
||||
<action id="EditorScrollBottom" class="com.intellij.openapi.editor.actions.ScrollToBottomAction"/>
|
||||
<action id="EditorMoveUpAndScroll" class="com.intellij.openapi.editor.actions.MoveUpAndScrollAction"/>
|
||||
|
||||
Reference in New Issue
Block a user