From 5991c4a01e1f1c451c7b6944485b744fbec019ab Mon Sep 17 00:00:00 2001 From: Anton Kozub Date: Tue, 2 Sep 2025 15:58:30 +0200 Subject: [PATCH] IDEA-370122 Logical Structure: support option "Always select opened element" GitOrigin-RevId: b16a09d5d45927996d02f6bb981663464a0fa55b --- platform/structure-view-impl/api-dump-experimental.txt | 3 ++- .../logical/impl/LogicalStructureViewModel.kt | 5 ++++- .../structureView/logical/model/ExtendedLogicalObject.kt | 8 +++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/platform/structure-view-impl/api-dump-experimental.txt b/platform/structure-view-impl/api-dump-experimental.txt index 4d639411828d..24dce7bb5c8f 100644 --- a/platform/structure-view-impl/api-dump-experimental.txt +++ b/platform/structure-view-impl/api-dump-experimental.txt @@ -11,7 +11,8 @@ *f:com.intellij.ide.structureView.logical.LogicalStructureTreeElementProvider$Companion - f:getTreeElement(java.lang.Object):com.intellij.ide.structureView.StructureViewTreeElement *:com.intellij.ide.structureView.logical.model.ExtendedLogicalObject -- a:isTheSameParent(java.lang.Object):Z +- canRepresentPsiElement(com.intellij.psi.PsiElement):Z +- isTheSameParent(java.lang.Object):Z *:com.intellij.ide.structureView.logical.model.LogicalContainer - a:getElements():java.util.List *a:com.intellij.ide.structureView.logical.model.LogicalModelPresentationProvider diff --git a/platform/structure-view-impl/src/com/intellij/ide/structureView/logical/impl/LogicalStructureViewModel.kt b/platform/structure-view-impl/src/com/intellij/ide/structureView/logical/impl/LogicalStructureViewModel.kt index c565e70e7fe8..e31224fd9c1a 100644 --- a/platform/structure-view-impl/src/com/intellij/ide/structureView/logical/impl/LogicalStructureViewModel.kt +++ b/platform/structure-view-impl/src/com/intellij/ide/structureView/logical/impl/LogicalStructureViewModel.kt @@ -90,7 +90,10 @@ class LogicalStructureViewModel private constructor(psiFile: PsiFile, editor: Ed if (treeElement.element == targetElement) { return TreeVisitor.Action.INTERRUPT } - else if (treeElement.element?.containingFile != targetElement.containingFile) { + (treeElement.getLogicalAssembledModel().model as? ExtendedLogicalObject)?.let { + if (it.canRepresentPsiElement(targetElement)) return TreeVisitor.Action.INTERRUPT + } + if (treeElement.element?.containingFile != targetElement.containingFile) { return TreeVisitor.Action.SKIP_CHILDREN } return TreeVisitor.Action.CONTINUE diff --git a/platform/structure-view-impl/src/com/intellij/ide/structureView/logical/model/ExtendedLogicalObject.kt b/platform/structure-view-impl/src/com/intellij/ide/structureView/logical/model/ExtendedLogicalObject.kt index d1a9b22ab184..13447cdc62c5 100644 --- a/platform/structure-view-impl/src/com/intellij/ide/structureView/logical/model/ExtendedLogicalObject.kt +++ b/platform/structure-view-impl/src/com/intellij/ide/structureView/logical/model/ExtendedLogicalObject.kt @@ -1,6 +1,7 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide.structureView.logical.model +import com.intellij.psi.PsiElement import org.jetbrains.annotations.ApiStatus /** @@ -14,6 +15,11 @@ interface ExtendedLogicalObject { * @return true - if elements are not equally themselves but are the same if threat them as parents. * This equality can break common rules for usual "equal", for example, symmetry rule */ - fun isTheSameParent(other: Any?): Boolean + fun isTheSameParent(other: Any?): Boolean = false + + /** + * If the element can represent additional elements different from what it is targeting + */ + fun canRepresentPsiElement(psiElement: PsiElement): Boolean = false } \ No newline at end of file