mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
IDEA-286201 Fix infinite search everywhere results for YAML keys
Add equality for found element items IJ-CR-20887 GitOrigin-RevId: 052ec550cd1399530034fc3fc19902c34281b8f8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3d6b5d2c09
commit
cbe6efe4d9
@@ -1,24 +1,29 @@
|
||||
// Copyright 2000-2018 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 org.jetbrains.yaml.navigation;
|
||||
|
||||
import com.intellij.ide.util.PsiNavigationSupport;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.NavigationItem;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.yaml.psi.impl.YAMLKeyValueImpl;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class YAMLKeyNavigationItem implements NavigationItem {
|
||||
private final Navigatable myNavigatable;
|
||||
private final String myName;
|
||||
private final VirtualFile myFile;
|
||||
private final @NotNull Navigatable myNavigatable;
|
||||
private final @NotNull String myName;
|
||||
private final @NotNull VirtualFile myFile;
|
||||
private final int myPosition;
|
||||
|
||||
YAMLKeyNavigationItem(@NotNull Navigatable navigatable, @NotNull String name, @NotNull VirtualFile file) {
|
||||
myNavigatable = navigatable;
|
||||
YAMLKeyNavigationItem(@NotNull Project project, @NotNull String name, @NotNull VirtualFile file, int position) {
|
||||
myNavigatable = PsiNavigationSupport.getInstance().createNavigatable(project, file, position);
|
||||
myName = name;
|
||||
myFile = file;
|
||||
myPosition = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,4 +70,17 @@ public class YAMLKeyNavigationItem implements NavigationItem {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
YAMLKeyNavigationItem item = (YAMLKeyNavigationItem)o;
|
||||
return myPosition == item.myPosition && myName.equals(item.myName) && myFile.equals(item.myFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(myName, myFile, myPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class YAMLKeysSearchEverywhereContributor implements SearchEverywhereCont
|
||||
Integer position = FileBasedIndex.getInstance().getFileData(YAMLKeysIndex.KEY, file, myProject).get(name);
|
||||
if (position != null) {
|
||||
Navigatable navigatable = PsiNavigationSupport.getInstance().createNavigatable(myProject, file, position);
|
||||
if (!consumer.process(new YAMLKeyNavigationItem(navigatable, name, file))) {
|
||||
if (!consumer.process(new YAMLKeyNavigationItem(myProject, name, file, position))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,8 @@ public class YAMLSearchEverywhereTest extends BasePlatformTestCase {
|
||||
for (String request : requests) {
|
||||
addRequestToResult(builder, request);
|
||||
ContributorSearchResult<YAMLKeyNavigationItem> result = contributor.search(request, new MockProgressIndicator(), 15);
|
||||
ContributorSearchResult<YAMLKeyNavigationItem> result2 = contributor.search(request, new MockProgressIndicator(), 15);
|
||||
assertEquals(result2.getItems(), result.getItems());
|
||||
for (YAMLKeyNavigationItem item : result.getItems()) {
|
||||
item.navigate(true);
|
||||
PsiElement element = myFixture.getElementAtCaret();
|
||||
|
||||
Reference in New Issue
Block a user