diff options
author | Michael Rennie | 2008-02-12 15:25:21 +0000 |
---|---|---|
committer | Michael Rennie | 2008-02-12 15:25:21 +0000 |
commit | f07aeeefc094ffb3ca411b7ba74a0f91e27c8e7a (patch) | |
tree | bc38b7b01971a3c63dfdb5b54a041568336efacf | |
parent | cd872f9e71c6c9fefa809a462035a94077d376e2 (diff) | |
download | eclipse.platform.debug-f07aeeefc094ffb3ca411b7ba74a0f91e27c8e7a.tar.gz eclipse.platform.debug-f07aeeefc094ffb3ca411b7ba74a0f91e27c8e7a.tar.xz eclipse.platform.debug-f07aeeefc094ffb3ca411b7ba74a0f91e27c8e7a.zip |
Bug 217769 [breakpoints] ToggleBreakpointAction always creates TextSelection with 0 lengh
-rw-r--r-- | org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ToggleBreakpointAction.java | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ToggleBreakpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ToggleBreakpointAction.java index 0927e262c..e828af06f 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ToggleBreakpointAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ToggleBreakpointAction.java @@ -22,6 +22,8 @@ import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.source.IVerticalRulerInfo; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; @@ -88,8 +90,7 @@ public class ToggleBreakpointAction extends Action implements IUpdate { return; try { - IRegion region = document.getLineInformation(line); - ITextSelection selection = new TextSelection(document, region.getOffset(), 0); + ITextSelection selection = getTextSelection(document, line); if (adapter instanceof IToggleBreakpointsTargetExtension) { IToggleBreakpointsTargetExtension extension = (IToggleBreakpointsTargetExtension) adapter; if (extension.canToggleBreakpoints(fPart, selection)) { @@ -172,8 +173,7 @@ public class ToggleBreakpointAction extends Action implements IUpdate { int line = fRulerInfo.getLineOfLastMouseButtonActivity(); if (line > -1) { try { - IRegion region = document.getLineInformation(line); - ITextSelection selection = new TextSelection(document, region.getOffset(), 0); + ITextSelection selection = getTextSelection(document, line); if (adapter instanceof IToggleBreakpointsTargetExtension) { IToggleBreakpointsTargetExtension extension = (IToggleBreakpointsTargetExtension) adapter; if (extension.canToggleBreakpoints(fPart, selection)) { @@ -195,5 +195,30 @@ public class ToggleBreakpointAction extends Action implements IUpdate { } setEnabled(false); } + + /** + * Determines the text selection for the breakpoint action. If clicking on the ruler inside + * the highlighted text, return the text selection for the highlighted text. Otherwise, + * return a text selection representing the start of the line. + * + * @param document The IDocument backing the Editor. + * @param line The line clicked on in the ruler. + * @return An ITextSelection as described. + * @throws BadLocationException If underlying operations throw. + */ + private ITextSelection getTextSelection(IDocument document, int line) throws BadLocationException { + IRegion region = document.getLineInformation(line); + ITextSelection textSelection = new TextSelection(document, region.getOffset(), 0); + ISelectionProvider provider = fPart.getSite().getSelectionProvider(); + if (provider != null){ + ISelection selection = provider.getSelection(); + if (selection instanceof ITextSelection + && ((ITextSelection) selection).getStartLine() <= line + && ((ITextSelection) selection).getEndLine() >= line) { + textSelection = (ITextSelection) selection; + } + } + return textSelection; + } } |