aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Azad2012-02-26 03:18:08 (EST)
committerDani Megert2012-02-26 03:19:39 (EST)
commit8fc5b67fd7594b88349285d7b446d55cf4337a0a (patch)
tree79297e1f0769ac8a4de98948b1559cbee8f4fc3a
parent595c559794cae95bc1abb0f33149e8574bc9bdb1 (diff)
downloadeclipse.jdt.ui-8fc5b67fd7594b88349285d7b446d55cf4337a0a.zip
eclipse.jdt.ui-8fc5b67fd7594b88349285d7b446d55cf4337a0a.tar.gz
eclipse.jdt.ui-8fc5b67fd7594b88349285d7b446d55cf4337a0a.tar.bz2
Fixed bug 40580: [navigation] Matching brace (Ctrl+Shift+P) should workv20120226-0819
anywhere in the file
-rw-r--r--org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaPairMatcherTest.java4
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java57
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.java1
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.properties1
4 files changed, 23 insertions, 40 deletions
diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaPairMatcherTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaPairMatcherTest.java
index 1151058..832c052 100644
--- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaPairMatcherTest.java
+++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaPairMatcherTest.java
@@ -141,11 +141,11 @@ public class JavaPairMatcherTest extends AbstractPairMatcherTest {
}
public void testEnclosingMatch() {
- IRegion match= fPairMatcher.findEnclosingPeerCharacters(fDocument, 4);
+ IRegion match= fPairMatcher.findEnclosingPeerCharacters(fDocument, 4, 0);
assertNotNull(match);
assertTrue(match.getOffset() == 2 && match.getLength() == 10);
- match= fPairMatcher.findEnclosingPeerCharacters(fDocument, 7);
+ match= fPairMatcher.findEnclosingPeerCharacters(fDocument, 7, 0);
assertNotNull(match);
assertTrue(match.getOffset() == 5 && match.getLength() == 4);
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java
index 4cc9b2f..f991ea0 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java
@@ -3660,23 +3660,12 @@ public abstract class JavaEditor extends AbstractDecoratedTextEditor implements
return;
IRegion selection= getSignedSelection(sourceViewer);
-
- int selectionLength= Math.abs(selection.getLength());
- if (selectionLength > 1) {
- setStatusLineErrorMessage(JavaEditorMessages.GotoMatchingBracket_error_invalidSelection);
- sourceViewer.getTextWidget().getDisplay().beep();
- return;
- }
-
- int sourceCaretOffset= selection.getOffset() + selection.getLength();
- int adjustment= getOffsetAdjustment(document, sourceCaretOffset, selection.getLength()); // handles non-zero selection
- sourceCaretOffset+= adjustment;
-
if (fPreviousSelections == null)
initializePreviousSelectionList();
- IRegion region= fBracketMatcher.match(document, sourceCaretOffset);
+
+ IRegion region= fBracketMatcher.match(document, selection.getOffset(), selection.getLength());
if (region == null) {
- region= fBracketMatcher.findEnclosingPeerCharacters(document, sourceCaretOffset);
+ region= fBracketMatcher.findEnclosingPeerCharacters(document, selection.getOffset(), selection.getLength());
initializePreviousSelectionList();
fPreviousSelections.add(selection);
} else {
@@ -3728,16 +3717,18 @@ public abstract class JavaEditor extends AbstractDecoratedTextEditor implements
return;
}
+ int adjustment= getOffsetAdjustment(document, selection.getOffset() + selection.getLength(), selection.getLength());
targetOffset+= adjustment;
- if (fPreviousSelections.size() == 1 && selection.getLength() < 0) {
+ int direction= (selection.getLength() == 0) ? 0 : ((selection.getLength() > 0) ? 1 : -1);
+ if (fPreviousSelections.size() == 1 && direction < 0) {
targetOffset++;
}
if (fPreviousSelections.size() > 0) {
- fPreviousSelections.add(new Region(targetOffset, selection.getLength()));
+ fPreviousSelections.add(new Region(targetOffset, direction));
}
- sourceViewer.setSelectedRange(targetOffset, selection.getLength());
- sourceViewer.revealRange(targetOffset, selection.getLength());
+ sourceViewer.setSelectedRange(targetOffset, direction);
+ sourceViewer.revealRange(targetOffset, direction);
}
private void initializePreviousSelectionList() {
@@ -3760,8 +3751,11 @@ public abstract class JavaEditor extends AbstractDecoratedTextEditor implements
return false;
}
+ /*
+ * Copy of org.eclipse.jface.text.source.DefaultCharacterPairMatcher.getOffsetAdjustment(IDocument, int, int)
+ */
private static int getOffsetAdjustment(IDocument document, int offset, int length) {
- if (length == 0)
+ if (length == 0 || Math.abs(length) > 1)
return 0;
try {
if (length < 0) {
@@ -3779,29 +3773,20 @@ public abstract class JavaEditor extends AbstractDecoratedTextEditor implements
return 0;
}
- /**
- * Returns the signed current selection.
- * The length will be negative if the resulting selection
- * is right-to-left (RtoL).
- * <p>
- * The selection offset is model based.
- * </p>
- *
- * @param sourceViewer the source viewer
- * @return a region denoting the current signed selection, for a resulting RtoL selections length is < 0
+ /*
+ * Copy of org.eclipse.jface.text.source.MatchingCharacterPainter.getSignedSelection(ISourceViewer)
*/
- protected IRegion getSignedSelection(ISourceViewer sourceViewer) {
+ private static final IRegion getSignedSelection(ISourceViewer sourceViewer) {
+ Point viewerSelection= sourceViewer.getSelectedRange();
+
StyledText text= sourceViewer.getTextWidget();
Point selection= text.getSelectionRange();
-
if (text.getCaretOffset() == selection.x) {
- selection.x= selection.x + selection.y;
- selection.y= -selection.y;
+ viewerSelection.x= viewerSelection.x + viewerSelection.y;
+ viewerSelection.y= -viewerSelection.y;
}
- selection.x= widgetOffset2ModelOffset(sourceViewer, selection.x);
-
- return new Region(selection.x, selection.y);
+ return new Region(viewerSelection.x, viewerSelection.y);
}
@Override
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.java
index 260d01a..1c7fd56 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.java
@@ -89,7 +89,6 @@ final class JavaEditorMessages extends NLS {
public static String ClassFileDocumentProvider_error_createElementInfo;
public static String ExpandSelectionMenu_label;
public static String GotoMatchingBracket_label;
- public static String GotoMatchingBracket_error_invalidSelection;
public static String GotoMatchingBracket_error_noMatchingBracket;
public static String GotoMatchingBracket_error_bracketOutsideSelectedElement;
public static String ShowInBreadcrumbAction_label;
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.properties
index 503e829..02d40c4 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorMessages.properties
@@ -70,7 +70,6 @@ ClassFileDocumentProvider_error_createElementInfo=ClassFileDocumentProvider.crea
ExpandSelectionMenu_label=E&xpand Selection To
GotoMatchingBracket_label= Matching &Bracket
-GotoMatchingBracket_error_invalidSelection=No bracket selected
GotoMatchingBracket_error_noMatchingBracket=No matching bracket found
GotoMatchingBracket_error_bracketOutsideSelectedElement=Matching bracket is outside the selected element