IDEA-131134 Support multiple breakpoints within on single line - preselect lambda...
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Thu, 18 Jun 2015 09:24:30 +0000 (12:24 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Thu, 18 Jun 2015 09:26:35 +0000 (12:26 +0300)
platform/xdebugger-api/src/com/intellij/xdebugger/breakpoints/XLineBreakpointType.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java

index 32e35eded48e3ca123ae210e362395d00fc1dae3..09b4a7b550e0f437044ad60a418d993fd664950a 100644 (file)
@@ -137,10 +137,13 @@ public abstract class XLineBreakpointType<P extends XBreakpointProperties> exten
   public abstract class XLineBreakpointVariant {
     public abstract String getText();
 
+    @Nullable
     public abstract Icon getIcon();
 
+    @Nullable
     public abstract TextRange getHighlightRange();
 
+    @Nullable
     public abstract P createProperties();
   }
 }
index 6f4a761df82d0a42fc0e4fd90f87855224553835..f55e80100183a197ce8f1165e380c8aab61d91e1 100644 (file)
@@ -189,6 +189,21 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
                   }
                 }
               }
+
+              // calculate default item
+              int caretOffset = editor.getCaretModel().getOffset();
+              XLineBreakpointType<P>.XLineBreakpointVariant defaultVariant = null;
+              for (XLineBreakpointType<P>.XLineBreakpointVariant variant : variants) {
+                TextRange range = variant.getHighlightRange();
+                if (range != null && range.contains(caretOffset)) {
+                  //noinspection ConstantConditions
+                  if (defaultVariant == null || defaultVariant.getHighlightRange().getLength() > range.getLength()) {
+                    defaultVariant = variant;
+                  }
+                }
+              }
+              final int defaultIndex = defaultVariant != null ? variants.indexOf(defaultVariant) : 0;
+
               final MySelectionListener selectionListener = new MySelectionListener();
               ListPopup popup = JBPopupFactory.getInstance().createListPopup(
                 new BaseListPopupStep<XLineBreakpointType.XLineBreakpointVariant>("Create breakpoint for", variants) {
@@ -220,6 +235,11 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
                     });
                     return FINAL_CHOICE;
                   }
+
+                  @Override
+                  public int getDefaultOptionIndex() {
+                    return defaultIndex;
+                  }
                 });
               popup.addListSelectionListener(selectionListener);
               popup.show(relativePoint);