From 0e85fa0ea4ee7e5c3a0e429088d71db9650bb5d4 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Tue, 19 Apr 2016 12:09:50 +0300 Subject: [PATCH] IDEA-154894 [api] ability for disabling scrolling on document changes into Editor --- .../src/com/intellij/openapi/editor/impl/EditorImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index 3025e4972691..fa2d861d102e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -132,6 +132,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi private static final Key PERMANENT_HEADER = Key.create("PERMANENT_HEADER"); public static final Key DO_DOCUMENT_UPDATE_TEST = Key.create("DoDocumentUpdateTest"); public static final Key FORCED_SOFT_WRAPS = Key.create("forced.soft.wraps"); + public static final Key DISABLE_CARET_POSITION_KEEPING = Key.create("editor.disable.caret.position.keeping"); private static final boolean HONOR_CAMEL_HUMPS_ON_TRIPLE_CLICK = Boolean.parseBoolean(System.getProperty("idea.honor.camel.humps.on.triple.click")); private static final Key BUFFER = Key.create("buffer"); private static final Color CURSOR_FOREGROUND_LIGHT = Gray._255; @@ -1894,7 +1895,9 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi repaintToScreenBottom(0); updateCaretCursor(); - restoreCaretRelativePosition(); + if (!Boolean.TRUE.equals(getUserData(DISABLE_CARET_POSITION_KEEPING))) { + restoreCaretRelativePosition(); + } } private void beforeChangedUpdate(@NotNull DocumentEvent e) { @@ -1962,7 +1965,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi repaintLines(startLine, endLine); } - if (getCaretModel().getOffset() < e.getOffset() || getCaretModel().getOffset() > e.getOffset() + e.getNewLength()){ + if (!Boolean.TRUE.equals(getUserData(DISABLE_CARET_POSITION_KEEPING)) && + (getCaretModel().getOffset() < e.getOffset() || getCaretModel().getOffset() > e.getOffset() + e.getNewLength())) { restoreCaretRelativePosition(); } }