diff options
author | Deepak Azad | 2012-02-10 10:29:09 +0000 |
---|---|---|
committer | Dani Megert | 2012-02-10 10:29:09 +0000 |
commit | a84b7b2087d40d3379292f09611cebb78a28e6be (patch) | |
tree | 82a8c283a94aab931f932e5efe68f07baeb22547 | |
parent | deaa20e93dbed9863a5338dfb61cd41b7a910a8d (diff) | |
download | eclipse.jdt.ui-a84b7b2087d40d3379292f09611cebb78a28e6be.tar.gz eclipse.jdt.ui-a84b7b2087d40d3379292f09611cebb78a28e6be.tar.xz eclipse.jdt.ui-a84b7b2087d40d3379292f09611cebb78a28e6be.zip |
Fixed bug 366400: [preferences][syntax highlighting] New preference tov20120210-1029
always show enclosing brackets
6 files changed, 123 insertions, 31 deletions
diff --git a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF index 9d6f64bcc1..baaf8cf32e 100644 --- a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF @@ -126,7 +126,7 @@ Require-Bundle: org.eclipse.jface.text;bundle-version="[3.7.0,4.0.0)", org.eclipse.ui;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui.console;bundle-version="[3.4.0,4.0.0)", - org.eclipse.ui.workbench.texteditor;bundle-version="[3.7.0,4.0.0)", + org.eclipse.ui.workbench.texteditor;bundle-version="[3.8.0,4.0.0)", org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui.views;bundle-version="[3.3.100,4.0.0)", org.eclipse.ui.editors;bundle-version="[3.5.0,4.0.0)", 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 94d847e80b..33a4812257 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 @@ -1528,6 +1528,10 @@ public abstract class JavaEditor extends AbstractDecoratedTextEditor implements /** Preference key for matching brackets */ protected final static String MATCHING_BRACKETS= PreferenceConstants.EDITOR_MATCHING_BRACKETS; + /** Preference key for highlighting bracket at caret location */ + protected final static String HIGHLIGHT_BRACKET_AT_CARET_LOCATION= PreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION; + /** Preference key for enclosing brackets */ + protected final static String ENCLOSING_BRACKETS= PreferenceConstants.EDITOR_ENCLOSING_BRACKETS; /** Preference key for matching brackets color */ protected final static String MATCHING_BRACKETS_COLOR= PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR; /** @@ -1768,6 +1772,12 @@ public abstract class JavaEditor extends AbstractDecoratedTextEditor implements */ private static final long ERROR_MESSAGE_TIMEOUT= 1000; + /** + * Previous location history for goto matching bracket action. + * + * @since 3.8 + */ + private List<IRegion> fPrevSelections; /** * Returns the most narrow java element including the given offset. @@ -3116,7 +3126,7 @@ public abstract class JavaEditor extends AbstractDecoratedTextEditor implements fBracketMatcher.setSourceVersion(getPreferenceStore().getString(JavaCore.COMPILER_SOURCE)); support.setCharacterPairMatcher(fBracketMatcher); - support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR); + support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR, HIGHLIGHT_BRACKET_AT_CARET_LOCATION, ENCLOSING_BRACKETS); super.configureSourceViewerDecorationSupport(support); } @@ -3647,13 +3657,35 @@ public abstract class JavaEditor extends AbstractDecoratedTextEditor implements return; } - // #26314 int sourceCaretOffset= selection.getOffset() + selection.getLength(); - if (isSurroundedByBrackets(document, sourceCaretOffset)) - sourceCaretOffset -= selection.getLength(); + int adjustment= getOffsetAdjustment(document, sourceCaretOffset, selection.getLength()); // handles non-zero selection + sourceCaretOffset+= adjustment; + if (fPrevSelections == null) + initializePrevSelectionList(); IRegion region= fBracketMatcher.match(document, sourceCaretOffset); if (region == null) { + region= fBracketMatcher.findEnclosingPeerCharacters(document, sourceCaretOffset); + initializePrevSelectionList(); + fPrevSelections.add(selection); + } else { + if (fPrevSelections.size() == 2) { + if (!selection.equals(fPrevSelections.get(1))) { + initializePrevSelectionList(); + } + } else if (fPrevSelections.size() == 3) { + if (selection.equals(fPrevSelections.get(2)) && !selection.equals(fPrevSelections.get(0))) { + IRegion originalSelection= fPrevSelections.get(0); + sourceViewer.setSelectedRange(originalSelection.getOffset(), originalSelection.getLength()); + sourceViewer.revealRange(originalSelection.getOffset(), originalSelection.getLength()); + initializePrevSelectionList(); + return; + } + initializePrevSelectionList(); + } + } + + if (region == null) { setStatusLineErrorMessage(JavaEditorMessages.GotoMatchingBracket_error_noMatchingBracket); sourceViewer.getTextWidget().getDisplay().beep(); return; @@ -3685,13 +3717,57 @@ public abstract class JavaEditor extends AbstractDecoratedTextEditor implements return; } - if (selection.getLength() < 0) - targetOffset -= selection.getLength(); + targetOffset+= adjustment; + if (fPrevSelections.size() == 1 && selection.getLength() < 0) { + targetOffset++; + } + if (fPrevSelections.size() > 0) { + fPrevSelections.add(new Region(targetOffset, selection.getLength())); + } sourceViewer.setSelectedRange(targetOffset, selection.getLength()); sourceViewer.revealRange(targetOffset, selection.getLength()); } + private void initializePrevSelectionList() { + fPrevSelections= new ArrayList<IRegion>(3); + } + + public static boolean isOpeningBracket(char character) { + for (int i= 0; i < BRACKETS.length; i+= 2) { + if (character == BRACKETS[i]) + return true; + } + return false; + } + + public static boolean isClosingBracket(char character) { + for (int i= 1; i < BRACKETS.length; i+= 2) { + if (character == BRACKETS[i]) + return true; + } + return false; + } + + private static int getOffsetAdjustment(IDocument document, int offset, int length) { + if (length == 0) + return 0; + try { + if (length < 0) { + if (isOpeningBracket(document.getChar(offset))) { + return 1; + } + } else { + if (isClosingBracket(document.getChar(offset - 1))) { + return -1; + } + } + } catch (BadLocationException e) { + //do nothing + } + return 0; + } + /** * Returns the signed current selection. * The length will be negative if the resulting selection @@ -3746,27 +3822,6 @@ public abstract class JavaEditor extends AbstractDecoratedTextEditor implements fCachedSelectedRange= getViewer().getSelectedRange(); } - private static boolean isBracket(char character) { - for (int i= 0; i != BRACKETS.length; ++i) - if (character == BRACKETS[i]) - return true; - return false; - } - - private static boolean isSurroundedByBrackets(IDocument document, int offset) { - if (offset == 0 || offset == document.getLength()) - return false; - - try { - return - isBracket(document.getChar(offset - 1)) && - isBracket(document.getChar(offset)); - - } catch (BadLocationException e) { - return false; - } - } - /** * {@inheritDoc} * <p> diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorAppearanceConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorAppearanceConfigurationBlock.java index f3f59dc7ce..5aaf90fd15 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorAppearanceConfigurationBlock.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorAppearanceConfigurationBlock.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -81,6 +81,8 @@ class JavaEditorAppearanceConfigurationBlock extends AbstractConfigurationBlock overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MATCHING_BRACKETS)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_ENCLOSING_BRACKETS)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_QUICKASSIST_LIGHTBULB)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS)); @@ -228,7 +230,15 @@ class JavaEditorAppearanceConfigurationBlock extends AbstractConfigurationBlock spacer.setLayoutData(gd); label= PreferencesMessages.JavaEditorPreferencePage_highlightMatchingBrackets; - addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_MATCHING_BRACKETS, 0); + Button master= addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_MATCHING_BRACKETS, 0); + + label= PreferencesMessages.JavaEditorPreferencePage_highlightBothBrackets; + Button slave= addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION, 0); + createDependency(master, slave); + + label= PreferencesMessages.JavaEditorPreferencePage_highlightEnclosingBrackets; + slave= addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_ENCLOSING_BRACKETS, 0); + createDependency(master, slave); label= PreferencesMessages.JavaEditorPreferencePage_quickassist_lightbulb; addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_QUICKASSIST_LIGHTBULB, 0); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java index 515ee772f8..e685eb37e6 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java @@ -150,6 +150,8 @@ public final class PreferencesMessages extends NLS { public static String JavaEditorPreferencePage_underline; public static String JavaEditorPreferencePage_enable; public static String JavaEditorPreferencePage_preview; + public static String JavaEditorPreferencePage_highlightBothBrackets; + public static String JavaEditorPreferencePage_highlightEnclosingBrackets; public static String JavaEditorPreferencePage_highlightMatchingBrackets; public static String JavaEditorPreferencePage_insertSingleProposalsAutomatically; public static String JavaEditorPreferencePage_showOnlyProposalsVisibleInTheInvocationContext; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties index ae972c436b..db6e1bc5be 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties @@ -130,6 +130,8 @@ JavaEditorPreferencePage_strikethrough=&Strikethrough JavaEditorPreferencePage_underline=&Underline JavaEditorPreferencePage_enable=Enab&le JavaEditorPreferencePage_preview=Previe&w: +JavaEditorPreferencePage_highlightBothBrackets=Highlight &bracket at caret location +JavaEditorPreferencePage_highlightEnclosingBrackets=Highlight &enclosing brackets JavaEditorPreferencePage_highlightMatchingBrackets=Highlight &matching brackets JavaEditorPreferencePage_insertSingleProposalsAutomatically=Insert single &proposals automatically JavaEditorPreferencePage_showOnlyProposalsVisibleInTheInvocationContext=Hide proposals not visible in the in&vocation context diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java index a3036e65d8..d0a5b11a7c 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -706,6 +706,27 @@ public class PreferenceConstants { public final static String EDITOR_MATCHING_BRACKETS= "matchingBrackets"; //$NON-NLS-1$ /** + * A named preference that controls whether bracket at caret location is highlighted or not. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 3.8 + */ + public final static String EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION= "highlightBracketAtCaretLocation"; //$NON-NLS-1$ + + /** + * A named preference that controls whether enclosing bracket matching highlighting is turned on + * or off. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 3.8 + */ + public final static String EDITOR_ENCLOSING_BRACKETS= "enclosingBrackets"; //$NON-NLS-1$ + + /** * A named preference that holds the color used to highlight matching brackets. * <p> * Value is of type <code>String</code>. A RGB color value encoded as a string @@ -3707,6 +3728,8 @@ public class PreferenceConstants { // JavaEditorPreferencePage store.setDefault(PreferenceConstants.EDITOR_MATCHING_BRACKETS, true); + store.setDefault(PreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION, false); + store.setDefault(PreferenceConstants.EDITOR_ENCLOSING_BRACKETS, false); store.setDefault(PreferenceConstants.EDITOR_CORRECTION_INDICATION, true); store.setDefault(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE, true); |