Index: libsrc/org/netbeans/editor/ext/ExtCaret.java
===================================================================
RCS file: /cvs/editor/libsrc/org/netbeans/editor/ext/ExtCaret.java,v
retrieving revision 1.47
diff -u -r1.47 ExtCaret.java
--- libsrc/org/netbeans/editor/ext/ExtCaret.java 19 Jan 2007 05:21:32 -0000 1.47
+++ libsrc/org/netbeans/editor/ext/ExtCaret.java 1 May 2007 03:14:55 -0000
@@ -80,6 +80,16 @@
/** Highlight matching brace draw layer visibility */
public static final int HIGHLIGHT_BRACE_LAYER_VISIBILITY = 11000;
+
+ /** Highlight a brace matching character before the caret */
+ public static final int MATCH_BRACE_BEFORE = -1;
+
+ /** Highlight a brace matching character after (at) the caret */
+ public static final int MATCH_BRACE_AFTER = 0;
+
+ /** Highlight a brace matching character either before or after caret;
+ the character before takes precedence. */
+ public static final int MATCH_BRACE_EITHER = java.lang.Integer.MAX_VALUE;
/** Whether to hightlight the matching brace */
boolean highlightBrace;
@@ -111,6 +121,8 @@
boolean simpleMatchBrace;
private boolean popupMenuEnabled;
+
+ private int matchBraceOffset = MATCH_BRACE_EITHER;
static final long serialVersionUID =-4292670043122577690L;
@@ -214,6 +226,32 @@
editorUI.removeLayer(HIGHLIGHT_BRACE_LAYER_NAME);
super.deinstall(c);
}
+
+ /** Set the match brace offset.
+ * @param offset One of MATCH_BRACE_BEFORE
,
+ * MATCH_BRACE_AFTER
* or MATCH_BRACE_EITHER
.
+ */
+ public void setMatchBraceOffset(int offset) {
+ if(offset != MATCH_BRACE_BEFORE && offset != MATCH_BRACE_AFTER
+ && offset != MATCH_BRACE_EITHER) {
+ throw new IllegalArgumentException("Offset "+ offset + " not allowed\n");
+ }
+ matchBraceOffset = offset;
+ BaseDocument doc = Utilities.getDocument(component);
+ if( doc != null ) {
+ doc.readLock();
+ try {
+ updateMatchBrace();
+ } finally {
+ doc.readUnlock();
+ }
+ }
+ }
+
+ /** Fetch the match brace offset. */
+ public int getMatchBraceOffset() {
+ return matchBraceOffset;
+ }
/** Update the matching brace of the caret. The document is read-locked
* while this method is called.
@@ -225,37 +263,43 @@
EditorUI editorUI = Utilities.getEditorUI(c);
BaseDocument doc = (BaseDocument)c.getDocument();
int dotPos = getDot();
+ ExtSyntaxSupport sup = (ExtSyntaxSupport)doc.getSyntaxSupport();
boolean madeValid = false; // whether brace marks display were validated
- if (dotPos > 0) {
- int[] matchBlk = ((ExtSyntaxSupport)doc.getSyntaxSupport())
- .findMatchingBlock(dotPos - 1, simpleMatchBrace);
- if (matchBlk != null) {
- if (highlightBraceStartMark != null) {
- int markStartPos = highlightBraceStartMark.getOffset();
- int markEndPos = highlightBraceEndMark.getOffset();
- if (markStartPos != matchBlk[0] || markEndPos != matchBlk[1]) {
- editorUI.repaintBlock(markStartPos, markEndPos);
- Utilities.moveMark(doc, highlightBraceStartMark, matchBlk[0]);
- Utilities.moveMark(doc, highlightBraceEndMark, matchBlk[1]);
+ int[] matchBlk = null;
+ if(dotPos > 0 && (matchBraceOffset == MATCH_BRACE_BEFORE
+ || matchBraceOffset == MATCH_BRACE_EITHER)) {
+ matchBlk = sup.findMatchingBlock(dotPos - 1, simpleMatchBrace);
+ }
+ if(matchBlk == null && (matchBraceOffset == MATCH_BRACE_AFTER
+ || matchBraceOffset == MATCH_BRACE_EITHER)) {
+ matchBlk = sup.findMatchingBlock(dotPos, simpleMatchBrace);
+ }
+ if (matchBlk != null) {
+ if (highlightBraceStartMark != null) {
+ int markStartPos = highlightBraceStartMark.getOffset();
+ int markEndPos = highlightBraceEndMark.getOffset();
+ if (markStartPos != matchBlk[0] || markEndPos != matchBlk[1]) {
+ editorUI.repaintBlock(markStartPos, markEndPos);
+ Utilities.moveMark(doc, highlightBraceStartMark, matchBlk[0]);
+ Utilities.moveMark(doc, highlightBraceEndMark, matchBlk[1]);
+ editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
+ } else { // on the same position
+ if (!braceMarksValid) { // was not valid, must repaint
editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
- } else { // on the same position
- if (!braceMarksValid) { // was not valid, must repaint
- editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
- }
}
- } else { // highlight mark is null
- highlightBraceStartMark = new MarkFactory.DrawMark(
- HIGHLIGHT_BRACE_LAYER_NAME, editorUI);
- highlightBraceEndMark = new MarkFactory.DrawMark(
- HIGHLIGHT_BRACE_LAYER_NAME, editorUI);
- highlightBraceStartMark.setActivateLayer(true);
- Utilities.insertMark(doc, highlightBraceStartMark, matchBlk[0]);
- Utilities.insertMark(doc, highlightBraceEndMark, matchBlk[1]);
- editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
}
- braceMarksValid = true;
- madeValid = true;
+ } else { // highlight mark is null
+ highlightBraceStartMark = new MarkFactory.DrawMark(
+ HIGHLIGHT_BRACE_LAYER_NAME, editorUI);
+ highlightBraceEndMark = new MarkFactory.DrawMark(
+ HIGHLIGHT_BRACE_LAYER_NAME, editorUI);
+ highlightBraceStartMark.setActivateLayer(true);
+ Utilities.insertMark(doc, highlightBraceStartMark, matchBlk[0]);
+ Utilities.insertMark(doc, highlightBraceEndMark, matchBlk[1]);
+ editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
}
+ braceMarksValid = true;
+ madeValid = true;
}
if (!madeValid) {
Index: libsrc/org/netbeans/editor/ext/ExtKit.java
===================================================================
RCS file: /cvs/editor/libsrc/org/netbeans/editor/ext/ExtKit.java,v
retrieving revision 1.71
diff -u -r1.71 ExtKit.java
--- libsrc/org/netbeans/editor/ext/ExtKit.java 1 Mar 2007 16:41:40 -0000 1.71
+++ libsrc/org/netbeans/editor/ext/ExtKit.java 1 May 2007 03:14:55 -0000
@@ -578,14 +578,25 @@
BaseDocument doc = Utilities.getDocument(target);
int dotPos = caret.getDot();
ExtSyntaxSupport sup = (ExtSyntaxSupport)doc.getSyntaxSupport();
- if (dotPos > 0) {
- int[] matchBlk = sup.findMatchingBlock(dotPos - 1, false);
- if (matchBlk != null) {
- if (select) {
- caret.moveDot(matchBlk[1]);
- } else {
- caret.setDot(matchBlk[1]);
- }
+ int[] matchBlk = null;
+ if(caret instanceof ExtCaret) {
+ int how = ((ExtCaret)caret).getMatchBraceOffset();
+ if(dotPos > 0 && (how == ExtCaret.MATCH_BRACE_BEFORE
+ || how == ExtCaret.MATCH_BRACE_EITHER)) {
+ matchBlk = sup.findMatchingBlock(dotPos - 1, false);
+ }
+ if(matchBlk == null && (how == ExtCaret.MATCH_BRACE_AFTER
+ || how == ExtCaret.MATCH_BRACE_EITHER)) {
+ matchBlk = sup.findMatchingBlock(dotPos, false);
+ }
+ } else if(dotPos > 0) {
+ matchBlk = sup.findMatchingBlock(dotPos - 1, false);
+ }
+ if (matchBlk != null) {
+ if (select) {
+ caret.moveDot(matchBlk[1]);
+ } else {
+ caret.setDot(matchBlk[1]);
}
}
} catch (BadLocationException e) {