121121import org .eclipse .jface .viewers .StructuredSelection ;
122122import org .eclipse .jface .window .Window ;
123123import org .eclipse .swt .SWT ;
124+ import org .eclipse .swt .events .SelectionAdapter ;
125+ import org .eclipse .swt .events .SelectionEvent ;
124126import org .eclipse .swt .graphics .Point ;
125127import org .eclipse .swt .widgets .Composite ;
126128import org .eclipse .swt .widgets .Display ;
127129import org .eclipse .swt .widgets .Event ;
128130import org .eclipse .swt .widgets .Shell ;
129131import org .eclipse .ui .IEditorInput ;
130132import org .eclipse .ui .IEditorPart ;
133+ import org .eclipse .ui .IWorkbenchPage ;
131134import org .eclipse .ui .IWorkbenchPart ;
135+ import org .eclipse .ui .IWorkbenchWindow ;
132136import org .eclipse .ui .PlatformUI ;
133137import org .eclipse .ui .dialogs .ElementListSelectionDialog ;
134138import org .eclipse .ui .dialogs .FilteredList ;
@@ -149,6 +153,7 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTargetExtensio
149153 private static final String LAMBDA_SEPARATOR = " " ; //$NON-NLS-1$
150154 private static final int MAX_LAMBDA_LINE_LENGTH = 25 ;
151155 private static final int MAX_TOTAL_LAMBDA_LINE_LENGTH = MAX_LAMBDA_LINE_LENGTH * 2 ;
156+ private static final String ZERO_WIDTH_SPACE = "\u200B " ; //$NON-NLS-1$
152157
153158 /**
154159 * Constructor
@@ -1964,14 +1969,36 @@ private static ICompilationUnit getCompilationUnit(ITextEditor editor) {
19641969 }
19651970
19661971 public int selectLambda (List <LambdaExpression > lambdaExps ) {
1967- List <String > lambdaNames = lambdaExps .stream ().map (expr -> shortenLambdaExpression (expr .toString ())).toList ();
1972+ Map <String , Integer > seen = new HashMap <>();
1973+ List <String > lambdaNames = lambdaExps .stream ().map (expr -> shortenLambdaExpression (expr .toString ())).map (name -> {
1974+ int count = seen .getOrDefault (name , 0 );
1975+ seen .put (name , count + 1 );
1976+ return count == 0 ? name : name + ZERO_WIDTH_SPACE .repeat (count );
1977+ }).toList ();
19681978 LambdaLabelProvider lambdaLabelProvider = new LambdaLabelProvider (lambdaExps , lambdaNames );
19691979 ElementListSelectionDialog dialog = new ElementListSelectionDialog (DebugUIPlugin .getShellForModalDialog (), lambdaLabelProvider ) {
19701980 @ Override
19711981 protected FilteredList createFilteredList (Composite parent ) {
19721982 FilteredList filteredList = super .createFilteredList (parent );
19731983 // Disable default sorting to keep the original order
19741984 filteredList .setComparator (new LambdaPositionComparator (lambdaNames ));
1985+ filteredList .addSelectionListener (new SelectionAdapter () {
1986+ @ Override
1987+ public void widgetSelected (SelectionEvent e ) {
1988+ int index = filteredList .getSelectionIndex ();
1989+ if (index >= 0 ) {
1990+ LambdaExpression lambda = lambdaExps .get (index );
1991+ int start = lambda .getStartPosition ();
1992+ int length = lambda .getLength ();
1993+ IWorkbenchWindow window = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ();
1994+ IWorkbenchPage page = window .getActivePage ();
1995+ IEditorPart editorPart = page .getActiveEditor ();
1996+ if (editorPart instanceof ITextEditor textEditor ) {
1997+ textEditor .selectAndReveal (start , length );
1998+ }
1999+ }
2000+ }
2001+ });
19752002 return filteredList ;
19762003 }
19772004
0 commit comments