From b69b771884c680408c6682a3a4d719ae56b0fa7d Mon Sep 17 00:00:00 2001 From: Viktor Shatrov Date: Mon, 28 Sep 2020 18:16:28 +0300 Subject: [PATCH] Inline debugger: Don't soft-wrap after line debugger hints (IDEA-251309) GitOrigin-RevId: 616877f04196579f57a506a302a5e4d22769cef1 --- .../intellij/openapi/editor/InlayModel.java | 7 ------- .../tree/injected/InlayModelWindow.java | 9 --------- .../editor/impl/AfterLineEndInlayImpl.java | 15 ++++++++++++-- .../openapi/editor/impl/InlayModelImpl.java | 20 +++++++++++++------ .../view/WrapElementMeasuringIterator.java | 5 +++++ .../textarea/TextComponentInlayModel.java | 8 -------- .../impl/inline/XDebuggerInlayUtil.java | 5 ++--- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/InlayModel.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/InlayModel.java index 1c74f0e8a830..e049f1dfc97a 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/InlayModel.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/InlayModel.java @@ -71,13 +71,6 @@ public interface InlayModel { @Nullable Inlay addAfterLineEndElement(int offset, boolean relatesToPrecedingText, @NotNull T renderer); - /** - * Same as {@link #addAfterLineEndElement(int, boolean, EditorCustomElementRenderer)}, - * but with an option to specify whether the inserted inlay should be the first or the last among other inlays on the same line - */ - @Nullable - Inlay addAfterLineEndElement(int offset, boolean relatesToPrecedingText, boolean insertFirst, @NotNull T renderer); - /** * Returns a list of inline elements for a given offset range (both limits are inclusive). Returned list is sorted by offset. * Both visible and invisible (due to folding) elements are returned. diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InlayModelWindow.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InlayModelWindow.java index b962257de191..bba26e44d17f 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InlayModelWindow.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InlayModelWindow.java @@ -46,15 +46,6 @@ final class InlayModelWindow implements InlayModel { return null; } - @Override - public @Nullable Inlay addAfterLineEndElement(int offset, - boolean relatesToPrecedingText, - boolean insertFirst, - @NotNull T renderer) { - logUnsupported(); - return null; - } - @NotNull @Override public List> getInlineElementsInRange(int startOffset, int endOffset) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/AfterLineEndInlayImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/AfterLineEndInlayImpl.java index 73c9ff367a8d..ca432cdf498a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/AfterLineEndInlayImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/AfterLineEndInlayImpl.java @@ -10,12 +10,19 @@ import org.jetbrains.annotations.NotNull; import java.awt.*; import java.util.List; -final class AfterLineEndInlayImpl extends InlayImpl> { +public final class AfterLineEndInlayImpl extends InlayImpl> { private static int ourGlobalCounter = 0; + private final boolean mySoftWrappable; final int myOrder; - AfterLineEndInlayImpl(@NotNull EditorImpl editor, int offset, boolean relatesToPrecedingText, boolean insertFirst, @NotNull R renderer) { + AfterLineEndInlayImpl(@NotNull EditorImpl editor, + int offset, + boolean relatesToPrecedingText, + boolean insertFirst, + boolean softWrappable, + @NotNull R renderer) { super(editor, offset, relatesToPrecedingText, renderer); + mySoftWrappable = softWrappable; //noinspection AssignmentToStaticFieldFromInstanceMethod int order = ourGlobalCounter++; myOrder = insertFirst ? -order : order; @@ -60,6 +67,10 @@ final class AfterLineEndInlayImpl extends return new VisualPosition(position.line, position.column + 1 + order); } + public boolean isSoftWrappable() { + return mySoftWrappable; + } + @Override public int getHeightInPixels() { return myEditor.getLineHeight(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayModelImpl.java index de3e90342952..1e04d9ecef88 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayModelImpl.java @@ -34,8 +34,9 @@ public final class InlayModelImpl implements InlayModel, PrioritizedDocumentList private static final Comparator BLOCK_ELEMENTS_COMPARATOR = Comparator.comparing((BlockInlayImpl i) -> i.getPlacement()) .thenComparing(i -> i.getPlacement() == Inlay.Placement.ABOVE_LINE ? i.myPriority : -i.myPriority); private static final Comparator AFTER_LINE_END_ELEMENTS_OFFSET_COMPARATOR = - Comparator.comparingInt((AfterLineEndInlayImpl i) -> i.getOffset()).thenComparingInt(i -> i.myOrder); - private static final Comparator AFTER_LINE_END_ELEMENTS_COMPARATOR = Comparator.comparingInt(i -> i.myOrder); + Comparator.comparingInt((AfterLineEndInlayImpl i) -> i.getOffset()).thenComparing(i -> !i.isSoftWrappable()).thenComparingInt(i -> i.myOrder); + private static final Comparator AFTER_LINE_END_ELEMENTS_COMPARATOR = + Comparator.comparing((AfterLineEndInlayImpl i) -> !i.isSoftWrappable()).thenComparingInt(i -> i.myOrder); private static final Processor UPDATE_PROCESSOR = inlay -> { inlay.update(); return true; @@ -150,18 +151,25 @@ public final class InlayModelImpl implements InlayModel, PrioritizedDocumentList public @NotNull Inlay addAfterLineEndElement(int offset, boolean relatesToPrecedingText, @NotNull T renderer) { - return addAfterLineEndElement(offset, relatesToPrecedingText, false, renderer); + return addAfterLineEndElement(offset, relatesToPrecedingText, false, true, renderer); } - @Override - public @NotNull Inlay addAfterLineEndElement(int offset, + + public @NotNull Inlay addInlineDebuggerHint(int offset, + boolean insertFirst, + @NotNull T renderer) { + return addAfterLineEndElement(offset, false, insertFirst, false, renderer); + } + + private @NotNull Inlay addAfterLineEndElement(int offset, boolean relatesToPrecedingText, boolean insertFirst, + boolean softWrappable, @NotNull T renderer) { EditorImpl.assertIsDispatchThread(); Document document = myEditor.getDocument(); offset = Math.max(0, Math.min(document.getTextLength(), offset)); - AfterLineEndInlayImpl inlay = new AfterLineEndInlayImpl<>(myEditor, offset, relatesToPrecedingText, insertFirst, renderer); + AfterLineEndInlayImpl inlay = new AfterLineEndInlayImpl<>(myEditor, offset, relatesToPrecedingText, insertFirst, softWrappable, renderer); notifyAdded(inlay); return inlay; } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/WrapElementMeasuringIterator.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/WrapElementMeasuringIterator.java index e5ddb40c6273..c8b5fd4ae7e6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/WrapElementMeasuringIterator.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/WrapElementMeasuringIterator.java @@ -4,6 +4,7 @@ package com.intellij.openapi.editor.impl.view; import com.intellij.openapi.editor.FoldRegion; import com.intellij.openapi.editor.Inlay; import com.intellij.openapi.editor.ex.util.EditorUtil; +import com.intellij.openapi.editor.impl.AfterLineEndInlayImpl; import com.intellij.openapi.editor.impl.softwrap.WrapElementIterator; import com.intellij.util.DocumentUtil; import org.jetbrains.annotations.NotNull; @@ -83,6 +84,10 @@ public final class WrapElementMeasuringIterator extends WrapElementIterator { int width = 0; while (afterLineEndInlayIndex < afterLineEndInlays.size()) { Inlay inlay = afterLineEndInlays.get(afterLineEndInlayIndex); + if (inlay instanceof AfterLineEndInlayImpl && !((AfterLineEndInlayImpl)inlay).isSoftWrappable()) { + afterLineEndInlayIndex++; + continue; + } int offset = inlay.getOffset(); if (offset < startOffset || offset > endOffset) break; width += inlay.getWidthInPixels(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentInlayModel.java b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentInlayModel.java index 3a94e8a6d8bf..c780030fc3c2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentInlayModel.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/textarea/TextComponentInlayModel.java @@ -40,14 +40,6 @@ final class TextComponentInlayModel implements InlayModel { return null; } - @Override - public @Nullable Inlay addAfterLineEndElement(int offset, - boolean relatesToPrecedingText, - boolean insertFirst, - @NotNull T renderer) { - return null; - } - @NotNull @Override public List> getInlineElementsInRange(int startOffset, int endOffset) { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/inline/XDebuggerInlayUtil.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/inline/XDebuggerInlayUtil.java index 7cdb18486b0d..3657e0541e22 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/inline/XDebuggerInlayUtil.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/inline/XDebuggerInlayUtil.java @@ -1,8 +1,6 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.xdebugger.impl.inline; -import com.intellij.codeInsight.daemon.impl.HighlightInfoType; -import com.intellij.facet.ModifiableFacetModel; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorCustomElementRenderer; @@ -11,6 +9,7 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.FontPreferences; import com.intellij.openapi.editor.impl.ComplementaryFontsRegistry; import com.intellij.openapi.editor.impl.FontInfo; +import com.intellij.openapi.editor.impl.InlayModelImpl; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -111,7 +110,7 @@ public final class XDebuggerInlayUtil { return false; }; InlineDebugRenderer renderer = new InlineDebugRenderer(variablePresentation, valueNode, view, isOnExecutionLine, onClick); - Inlay inlay = e.getInlayModel().addAfterLineEndElement(offset, false, customNode, renderer); + Inlay inlay = ((InlayModelImpl)e.getInlayModel()).addInlineDebuggerHint(offset, customNode, renderer); if (customNode) { ((InlineWatchNodeImpl)valueNode).inlayCreated(inlay); }