mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-122331 Cannot set breakpoints on multiple selections
This commit is contained in:
@@ -19,6 +19,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
@@ -187,6 +188,27 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
|
||||
return XSourcePositionImpl.create(file, line);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<XSourcePosition> getAllCaretsPositions(@NotNull Project project, DataContext context) {
|
||||
Editor editor = getEditor(project, context);
|
||||
if (editor == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final Document document = editor.getDocument();
|
||||
VirtualFile file = FileDocumentManager.getInstance().getFile(document);
|
||||
Collection<XSourcePosition> res = new ArrayList<XSourcePosition>();
|
||||
List<Caret> carets = editor.getCaretModel().getAllCarets();
|
||||
for (Caret caret : carets) {
|
||||
int line = caret.getLogicalPosition().line;
|
||||
XSourcePositionImpl position = XSourcePositionImpl.create(file, line);
|
||||
if (position != null) {
|
||||
res.add(position);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Editor getEditor(@NotNull Project project, DataContext context) {
|
||||
Editor editor = CommonDataKeys.EDITOR.getData(context);
|
||||
|
||||
+10
-7
@@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.xdebugger.XDebuggerManager;
|
||||
import com.intellij.xdebugger.XDebuggerUtil;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
@@ -30,6 +31,8 @@ import com.intellij.xdebugger.impl.actions.DebuggerActionHandler;
|
||||
import com.intellij.xdebugger.impl.breakpoints.XBreakpointUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
@@ -58,13 +61,13 @@ public class XToggleLineBreakpointActionHandler extends DebuggerActionHandler {
|
||||
}
|
||||
|
||||
public void perform(@NotNull final Project project, final AnActionEvent event) {
|
||||
XSourcePosition position = XDebuggerUtilImpl.getCaretPosition(project, event.getDataContext());
|
||||
if (position == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Editor editor = event.getData(CommonDataKeys.EDITOR);
|
||||
|
||||
XBreakpointUtil.toggleLineBreakpoint(project, position.getFile(), editor, position.getLine(), myTemporary, true);
|
||||
// do not toggle more than once on the same line
|
||||
Set<Integer> processedLines = new HashSet<Integer>();
|
||||
for (XSourcePosition position : XDebuggerUtilImpl.getAllCaretsPositions(project, event.getDataContext())) {
|
||||
if (processedLines.add(position.getLine())) {
|
||||
XBreakpointUtil.toggleLineBreakpoint(project, position.getFile(), editor, position.getLine(), myTemporary, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user