From 2d5ea8423983b115864f969a3224468fd0b9b2b2 Mon Sep 17 00:00:00 2001 From: "Ivan.Yarkov" Date: Wed, 5 Nov 2025 20:14:40 +0200 Subject: [PATCH] RIDER-131949 perform typing on the frontend to fix wrap on typing when limit is exceeded (cherry picked from commit 506d38464fdf531af039d0d89b4ce155f0c17659) IJ-MR-181537 GitOrigin-RevId: 8aca1989aed95329916d583b61fe09a79f00c116 --- platform/lang-impl/api-dump-unreviewed.txt | 5 ----- platform/lang-impl/api-dump.txt | 6 ++++++ .../editorActions/AutoHardWrapHandler.java | 11 ++++++----- .../src/META-INF/LangExtensions.xml | 1 + 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/platform/lang-impl/api-dump-unreviewed.txt b/platform/lang-impl/api-dump-unreviewed.txt index e7c1b4f87157..22405cf7c828 100644 --- a/platform/lang-impl/api-dump-unreviewed.txt +++ b/platform/lang-impl/api-dump-unreviewed.txt @@ -2611,11 +2611,6 @@ f:com.intellij.codeInsight.documentation.QuickDocUtil - s:inferLinkFromFullDocumentation(com.intellij.lang.documentation.DocumentationProvider,com.intellij.psi.PsiElement,com.intellij.psi.PsiElement,java.lang.String):java.lang.String - s:updateQuickDoc(com.intellij.openapi.project.Project,com.intellij.psi.PsiElement,java.lang.String):V - s:updateQuickDocAsync(com.intellij.psi.PsiElement,java.lang.CharSequence,com.intellij.util.Consumer):V -f:com.intellij.codeInsight.editorActions.AutoHardWrapHandler -- sf:AUTO_WRAP_LINE_IN_PROGRESS_KEY:com.intellij.openapi.util.Key -- ():V -- s:getInstance():com.intellij.codeInsight.editorActions.AutoHardWrapHandler -- wrapLineIfNecessary(com.intellij.openapi.editor.Editor,com.intellij.openapi.actionSystem.DataContext,J):V c:com.intellij.codeInsight.editorActions.BackspaceHandler - com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler$ForEachCaret - pf:myOriginalHandler:com.intellij.openapi.editor.actionSystem.EditorActionHandler diff --git a/platform/lang-impl/api-dump.txt b/platform/lang-impl/api-dump.txt index da2761e4e2db..497456bf5283 100644 --- a/platform/lang-impl/api-dump.txt +++ b/platform/lang-impl/api-dump.txt @@ -145,6 +145,12 @@ com.intellij.codeInsight.documentation.DocumentationActionProvider - sf:EP_NAME:com.intellij.openapi.extensions.ExtensionPointName - additionalActions(com.intellij.codeInsight.documentation.DocumentationComponent):java.util.List - additionalActions(com.intellij.openapi.editor.Editor,com.intellij.psi.PsiDocCommentBase,java.lang.String):java.util.List +c:com.intellij.codeInsight.editorActions.AutoHardWrapHandler +- sf:AUTO_WRAP_LINE_IN_PROGRESS_KEY:com.intellij.openapi.util.Key +- ():V +- s:getInstance():com.intellij.codeInsight.editorActions.AutoHardWrapHandler +- p:preprocessLineWrap(com.intellij.openapi.editor.Editor):V +- wrapLineIfNecessary(com.intellij.openapi.editor.Editor,com.intellij.openapi.actionSystem.DataContext,J):V com.intellij.codeInsight.editorActions.CodeBlockProvider - a:getCodeBlockRange(com.intellij.openapi.editor.Editor,com.intellij.psi.PsiFile):com.intellij.openapi.util.TextRange com.intellij.codeInsight.editorActions.CommentCompleteHandler diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/AutoHardWrapHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/AutoHardWrapHandler.java index 4a22d257a87e..67252d7c584b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/AutoHardWrapHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/AutoHardWrapHandler.java @@ -7,6 +7,7 @@ import com.intellij.ide.DataManager; import com.intellij.lang.Language; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.actionSystem.EditorActionManager; import com.intellij.openapi.editor.event.DocumentEvent; @@ -26,7 +27,7 @@ import java.util.WeakHashMap; /** * Encapsulates logic for processing {@link EditorSettings#isWrapWhenTypingReachesRightMargin(Project)} option. */ -public final class AutoHardWrapHandler { +public class AutoHardWrapHandler { /** * This key is used as a flag that indicates if {@code 'auto wrap line on typing'} activity is performed now. @@ -35,8 +36,6 @@ public final class AutoHardWrapHandler { */ public static final Key AUTO_WRAP_LINE_IN_PROGRESS_KEY = new Key<>("AUTO_WRAP_LINE_IN_PROGRESS"); - private static final AutoHardWrapHandler INSTANCE = new AutoHardWrapHandler(); - /** * There is a possible case that the user configured editor to * {@link EditorSettings#isWrapWhenTypingReachesRightMargin(Project) wrap line on reaching right margin} and that he or she @@ -50,7 +49,7 @@ public final class AutoHardWrapHandler { private final Map myAutoWrapChanges = new WeakHashMap<>(); public static AutoHardWrapHandler getInstance() { - return INSTANCE; + return ApplicationManager.getApplication().getService(AutoHardWrapHandler.class); } /** @@ -181,7 +180,7 @@ public final class AutoHardWrapHandler { return event.getNewLength() <= event.getOldLength() && endsWithSpaces; } }; - + preprocessLineWrap(editor); caretModel.moveToOffset(wrapOffset); DataManager.getInstance().saveInDataContext(dataContext, AUTO_WRAP_LINE_IN_PROGRESS_KEY, true); document.addDocumentListener(listener); @@ -202,6 +201,8 @@ public final class AutoHardWrapHandler { caretModel.moveToOffset(baseCaretOffset + caretOffsetDiff[0]); } + protected void preprocessLineWrap(@NotNull Editor editor) {} + private static final class AutoWrapChange { final TextChangeImpl change = new TextChangeImpl("", 0, 0); diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index f3ed1222491a..869ab7c5adb3 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -363,6 +363,7 @@ +