Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Azad2012-02-10 10:27:51 +0000
committerDani Megert2012-02-10 10:27:51 +0000
commitb8d0417ed59519a46d28cac812ad3b7393dd83e9 (patch)
tree163e5f5c761fa497dc6f600ecbfc0d5d9cbb3a39 /org.eclipse.jface.text/src/org/eclipse/jface/text
parentf7e9c6e267deffe8ad723ad4b8c99d360e585a7b (diff)
downloadeclipse.platform.text-b8d0417ed59519a46d28cac812ad3b7393dd83e9.tar.gz
eclipse.platform.text-b8d0417ed59519a46d28cac812ad3b7393dd83e9.tar.xz
eclipse.platform.text-b8d0417ed59519a46d28cac812ad3b7393dd83e9.zip
Fixed bug 366400: [preferences][syntax highlighting] New preference tov20120210-1027
always show enclosing brackets
Diffstat (limited to 'org.eclipse.jface.text/src/org/eclipse/jface/text')
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java30
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java20
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java38
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java52
4 files changed, 123 insertions, 17 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java
index 7b4b9e64bba..c329c61f04f 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java
@@ -29,7 +29,7 @@ import org.eclipse.jface.text.TextUtilities;
*
* @since 3.3
*/
-public class DefaultCharacterPairMatcher implements ICharacterPairMatcher {
+public class DefaultCharacterPairMatcher implements ICharacterPairMatcher, ICharacterPairMatcherExtension {
private int fAnchor= -1;
private final CharPairs fPairs;
@@ -107,6 +107,34 @@ public class DefaultCharacterPairMatcher implements ICharacterPairMatcher {
}
}
+ /**
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcherExtension#findEnclosingPeerCharacters(org.eclipse.jface.text.IDocument,
+ * int)
+ * @since 3.8
+ */
+ public IRegion findEnclosingPeerCharacters(IDocument doc, int offset) {
+ if (doc == null || offset < 0 || offset > doc.getLength())
+ return null;
+ try {
+ for (int offset1= offset; offset1 >= 0; offset1--) {
+ char prevChar= doc.getChar(Math.max(offset1 - 1, 0));
+ if (fPairs.contains(prevChar) && fPairs.isStartCharacter(prevChar)) {
+ IRegion match= performMatch(doc, offset1);
+ if (match != null) {
+ int matchOffset= match.getOffset();
+ int matchLength= match.getLength();
+ if ((matchOffset <= offset) && (matchOffset + matchLength > offset)) {
+ return match;
+ }
+ }
+ }
+ }
+ } catch (BadLocationException ble) {
+ return null;
+ }
+ return null;
+ }
+
/*
* Performs the actual work of matching for #match(IDocument, int).
*/
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
index 09ca2a4ce50..b969b8fa4c4 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 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
@@ -14,15 +14,15 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
/**
- * A character pair matcher finds to a character at a certain document offset
- * the matching peer character. It is the matchers responsibility to define the
- * concepts of "matching" and "peer". The matching process starts at a given
- * offset. Starting of this offset, the matcher chooses a character close to
- * this offset. The anchor defines whether the chosen character is left or right
- * of the initial offset. The matcher then searches for the matching peer
- * character of the chosen character and if it finds one, delivers the minimal
- * region of the document that contains both characters.
- *
+ * A character pair matcher finds to a character at a certain document offset the matching peer
+ * character. It is the matchers responsibility to define the concepts of "matching" and "peer". The
+ * matching process starts at a given offset. Starting of this offset, the matcher chooses a
+ * character close to this offset. The anchor defines whether the chosen character is left or right
+ * of the initial offset. The matcher then searches for the matching peer character of the chosen
+ * character and if it finds one, delivers the minimal region of the document that contains both
+ * characters.
+ *
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcherExtension
* @since 2.1
*/
public interface ICharacterPairMatcher {
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java
new file mode 100644
index 00000000000..f5c114b0bfa
--- /dev/null
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.source;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+
+/**
+ * Extension interface {@link org.eclipse.jface.text.source.ICharacterPairMatcher}.
+ * <p>
+ * Extends the character pair matcher with the concept of enclosing peer characters at a caret
+ * offset.
+ *
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcher
+ * @since 3.8
+ */
+public interface ICharacterPairMatcherExtension {
+
+ /**
+ * Starting at the given offset, the matcher searches for a pair of enclosing peer characters
+ * and if it finds one, returns the minimal region of the document that contains the pair.
+ *
+ * It returns <code>null</code> if there is no enclosing pair.
+ *
+ * @param iDocument the document to work on
+ * @param i the start offset
+ * @return the minimal region containing the peer characters
+ */
+ IRegion findEnclosingPeerCharacters(IDocument iDocument, int i);
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java
index 0306bcae9a5..783bd0699e7 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 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
@@ -55,6 +55,12 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
private Position fPairPosition= new Position(0, 0);
/** The anchor indicating whether the character is left or right of the caret */
private int fAnchor;
+ /** Whether to highlight enclosing peer characters or not. */
+ private boolean fHighlightEnclosingPeerCharcters;
+ /** Whether to highlight the character at caret location or not. */
+ private boolean fHighlightCharacterAtCaretLocation;
+ /** Whether a character is present at caret location or not. */
+ private boolean fCharacterPresentAtCaretLocation;
/**
@@ -72,6 +78,27 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
}
/**
+ * Sets whether to highlight the character at caret location or not.
+ *
+ * @param highlightCharacterAtCaretLocation whether to highlight the character at caret location
+ * or not
+ * @since 3.8
+ */
+ public void setHighlightCharacterAtCaretLocation(boolean highlightCharacterAtCaretLocation) {
+ fHighlightCharacterAtCaretLocation= highlightCharacterAtCaretLocation;
+ }
+
+ /**
+ * Sets whether to highlight enclosing peer characters or not.
+ *
+ * @param highlightEnclosingPeerCharcters whether to highlight enclosing peer characters or not
+ * @since 3.8
+ */
+ public void setHighlightEnclosingPeerCharacters(boolean highlightEnclosingPeerCharcters) {
+ fHighlightEnclosingPeerCharcters= highlightEnclosingPeerCharcters;
+ }
+
+ /**
* Sets the color in which to highlight the match character.
*
* @param color the color
@@ -158,10 +185,15 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
offset -= region.getOffset();
}
- if (ICharacterPairMatcher.RIGHT == fAnchor)
+ if (fHighlightCharacterAtCaretLocation || (fHighlightEnclosingPeerCharcters && !fCharacterPresentAtCaretLocation)) {
draw(gc, offset, 1);
- else
- draw(gc, offset + length -1, 1);
+ draw(gc, offset + length - 1, 1);
+ } else {
+ if (ICharacterPairMatcher.RIGHT == fAnchor)
+ draw(gc, offset, 1);
+ else
+ draw(gc, offset + length - 1, 1);
+ }
}
/**
@@ -218,6 +250,12 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
}
IRegion pair= fMatcher.match(document, selection.x);
+ boolean characterPresentAtCaretLocation= (pair != null);
+ if (pair == null && fHighlightEnclosingPeerCharcters && fMatcher instanceof ICharacterPairMatcherExtension) {
+ ICharacterPairMatcherExtension matcher= (ICharacterPairMatcherExtension)fMatcher;
+ pair= matcher.findEnclosingPeerCharacters(document, selection.x);
+ }
+
if (pair == null) {
deactivate(true);
return;
@@ -232,8 +270,8 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
} else if (pair.getOffset() != fPairPosition.getOffset() ||
pair.getLength() != fPairPosition.getLength() ||
- fMatcher.getAnchor() != fAnchor) {
-
+ fMatcher.getAnchor() != fAnchor ||
+ characterPresentAtCaretLocation != fCharacterPresentAtCaretLocation) {
// otherwise only do something if position is different
// remove old highlighting
@@ -243,6 +281,7 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
fPairPosition.offset= pair.getOffset();
fPairPosition.length= pair.getLength();
fAnchor= fMatcher.getAnchor();
+ fCharacterPresentAtCaretLocation= characterPresentAtCaretLocation;
// apply new highlighting
handleDrawRequest(null);
@@ -255,6 +294,7 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
fPairPosition.offset= pair.getOffset();
fPairPosition.length= pair.getLength();
fAnchor= fMatcher.getAnchor();
+ fCharacterPresentAtCaretLocation= characterPresentAtCaretLocation;
fTextWidget.addPaintListener(this);
fPaintPositionManager.managePosition(fPairPosition);

Back to the top