mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix scrolling to caret at the end of soft wrapped line
This commit is contained in:
+20
-7
@@ -30,6 +30,7 @@ import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.LogicalPosition;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.editor.VisualPosition;
|
||||
import com.intellij.openapi.editor.event.DocumentAdapter;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
import com.intellij.openapi.editor.event.VisibleAreaEvent;
|
||||
@@ -135,9 +136,23 @@ public class ScrollingModelImpl implements ScrollingModelEx {
|
||||
@Override
|
||||
public void scrollToCaret(@NotNull ScrollType scrollType) {
|
||||
assertIsDispatchThread();
|
||||
LogicalPosition caretPosition = myEditor.getCaretModel().getLogicalPosition();
|
||||
myEditor.validateSize();
|
||||
scrollTo(caretPosition, scrollType);
|
||||
if (myEditor.myUseNewRendering) {
|
||||
VisualPosition caretPosition = myEditor.getCaretModel().getVisualPosition();
|
||||
scrollTo(caretPosition, scrollType);
|
||||
}
|
||||
else {
|
||||
LogicalPosition caretPosition = myEditor.getCaretModel().getLogicalPosition();
|
||||
scrollTo(caretPosition, scrollType);
|
||||
}
|
||||
}
|
||||
|
||||
private void scrollTo(@NotNull VisualPosition pos, @NotNull ScrollType scrollType) {
|
||||
AnimatedScrollingRunnable canceledThread = cancelAnimatedScrolling(false);
|
||||
Rectangle viewRect = canceledThread != null ? canceledThread.getTargetVisibleArea() : getVisibleArea();
|
||||
Point targetLocation = myEditor.visualPositionToXY(pos);
|
||||
Point p = calcOffsetsToScroll(targetLocation, scrollType, viewRect);
|
||||
scrollToOffsets(p.x, p.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,8 +161,8 @@ public class ScrollingModelImpl implements ScrollingModelEx {
|
||||
|
||||
AnimatedScrollingRunnable canceledThread = cancelAnimatedScrolling(false);
|
||||
Rectangle viewRect = canceledThread != null ? canceledThread.getTargetVisibleArea() : getVisibleArea();
|
||||
|
||||
Point p = calcOffsetsToScroll(pos, scrollType, viewRect);
|
||||
Point targetLocation = myEditor.logicalPositionToXY(pos);
|
||||
Point p = calcOffsetsToScroll(targetLocation, scrollType, viewRect);
|
||||
scrollToOffsets(p.x, p.y);
|
||||
}
|
||||
|
||||
@@ -177,9 +192,7 @@ public class ScrollingModelImpl implements ScrollingModelEx {
|
||||
myAnimationDisabled = false;
|
||||
}
|
||||
|
||||
private Point calcOffsetsToScroll(LogicalPosition pos, ScrollType scrollType, Rectangle viewRect) {
|
||||
Point targetLocation = myEditor.logicalPositionToXY(pos);
|
||||
|
||||
private Point calcOffsetsToScroll(Point targetLocation, ScrollType scrollType, Rectangle viewRect) {
|
||||
if (myEditor.getSettings().isRefrainFromScrolling() && viewRect.contains(targetLocation)) {
|
||||
if (scrollType == ScrollType.CENTER ||
|
||||
scrollType == ScrollType.CENTER_DOWN ||
|
||||
|
||||
@@ -319,4 +319,14 @@ public class EditorImplTest extends AbstractEditorTest {
|
||||
up();
|
||||
checkResultByText("abc\nd<caret>ef\nghi");
|
||||
}
|
||||
|
||||
public void testScrollingToCaretAtSoftWrap() throws Exception {
|
||||
initText("looooooooooooooooong wooooooooooooooooords");
|
||||
configureSoftWraps(10);
|
||||
end();
|
||||
VisualPosition caretPosition = myEditor.getCaretModel().getCurrentCaret().getVisualPosition();
|
||||
Point caretPoint = myEditor.visualPositionToXY(caretPosition);
|
||||
Rectangle visibleArea = myEditor.getScrollingModel().getVisibleArea();
|
||||
assertTrue(visibleArea.contains(caretPoint));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user