This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 95126
Collapse All | Expand All

(-)libsrc/org/netbeans/editor/ext/ExtCaret.java (-26 / +70 lines)
Lines 80-85 Link Here
80
80
81
    /** Highlight matching brace draw layer visibility */
81
    /** Highlight matching brace draw layer visibility */
82
    public static final int HIGHLIGHT_BRACE_LAYER_VISIBILITY = 11000;
82
    public static final int HIGHLIGHT_BRACE_LAYER_VISIBILITY = 11000;
83
    
84
    /** Highlight a brace matching character before the caret */
85
    public static final int MATCH_BRACE_BEFORE = -1;
86
    
87
    /** Highlight a brace matching character after (at) the caret */
88
    public static final int MATCH_BRACE_AFTER = 0;
89
    
90
    /** Highlight a brace matching character either before or after caret;
91
        the character before takes precedence. */
92
    public static final int MATCH_BRACE_EITHER = java.lang.Integer.MAX_VALUE;
83
93
84
    /** Whether to hightlight the matching brace */
94
    /** Whether to hightlight the matching brace */
85
    boolean highlightBrace;
95
    boolean highlightBrace;
Lines 111-116 Link Here
111
    boolean simpleMatchBrace;
121
    boolean simpleMatchBrace;
112
    
122
    
113
    private boolean popupMenuEnabled;
123
    private boolean popupMenuEnabled;
124
    
125
    private int matchBraceOffset = MATCH_BRACE_EITHER;
114
126
115
    static final long serialVersionUID =-4292670043122577690L;
127
    static final long serialVersionUID =-4292670043122577690L;
116
128
Lines 214-219 Link Here
214
        editorUI.removeLayer(HIGHLIGHT_BRACE_LAYER_NAME);
226
        editorUI.removeLayer(HIGHLIGHT_BRACE_LAYER_NAME);
215
        super.deinstall(c);
227
        super.deinstall(c);
216
    }
228
    }
229
    
230
    /** Set the match brace offset.
231
     * @param offset One of <code>MATCH_BRACE_BEFORE</code>,
232
     * <code>MATCH_BRACE_AFTER</code> * or <code>MATCH_BRACE_EITHER</code>.
233
     */
234
    public void setMatchBraceOffset(int offset) {
235
        if(offset != MATCH_BRACE_BEFORE && offset != MATCH_BRACE_AFTER
236
           && offset != MATCH_BRACE_EITHER) {
237
            throw new IllegalArgumentException("Offset "+ offset + " not allowed\n");
238
        }
239
        matchBraceOffset = offset;
240
        BaseDocument doc = Utilities.getDocument(component);
241
        if( doc != null ) {
242
            doc.readLock();
243
            try {
244
                updateMatchBrace();
245
            } finally {
246
                doc.readUnlock();
247
            }
248
        }
249
    }
250
    
251
    /** Fetch the match brace offset. */
252
    public int getMatchBraceOffset() {
253
        return matchBraceOffset;
254
    }
217
255
218
    /** Update the matching brace of the caret. The document is read-locked
256
    /** Update the matching brace of the caret. The document is read-locked
219
     * while this method is called.
257
     * while this method is called.
Lines 225-261 Link Here
225
                EditorUI editorUI = Utilities.getEditorUI(c);
263
                EditorUI editorUI = Utilities.getEditorUI(c);
226
                BaseDocument doc = (BaseDocument)c.getDocument();
264
                BaseDocument doc = (BaseDocument)c.getDocument();
227
                int dotPos = getDot();
265
                int dotPos = getDot();
266
                ExtSyntaxSupport sup = (ExtSyntaxSupport)doc.getSyntaxSupport();
228
                boolean madeValid = false; // whether brace marks display were validated
267
                boolean madeValid = false; // whether brace marks display were validated
229
                if (dotPos > 0) {
268
                int[] matchBlk = null;
230
                    int[] matchBlk = ((ExtSyntaxSupport)doc.getSyntaxSupport())
269
                if(dotPos > 0 && (matchBraceOffset == MATCH_BRACE_BEFORE
231
                        .findMatchingBlock(dotPos - 1, simpleMatchBrace);
270
                                  || matchBraceOffset == MATCH_BRACE_EITHER)) {
232
                    if (matchBlk != null) {
271
                    matchBlk = sup.findMatchingBlock(dotPos - 1, simpleMatchBrace);
233
                        if (highlightBraceStartMark != null) {
272
                }
234
                            int markStartPos = highlightBraceStartMark.getOffset();
273
                if(matchBlk == null && (matchBraceOffset == MATCH_BRACE_AFTER
235
                            int markEndPos = highlightBraceEndMark.getOffset();
274
                                        || matchBraceOffset == MATCH_BRACE_EITHER)) {
236
                            if (markStartPos != matchBlk[0] || markEndPos != matchBlk[1]) {
275
                    matchBlk = sup.findMatchingBlock(dotPos, simpleMatchBrace);
237
                                editorUI.repaintBlock(markStartPos, markEndPos);
276
                }
238
                                Utilities.moveMark(doc, highlightBraceStartMark, matchBlk[0]);
277
                if (matchBlk != null) {
239
                                Utilities.moveMark(doc, highlightBraceEndMark, matchBlk[1]);
278
                    if (highlightBraceStartMark != null) {
279
                        int markStartPos = highlightBraceStartMark.getOffset();
280
                        int markEndPos = highlightBraceEndMark.getOffset();
281
                        if (markStartPos != matchBlk[0] || markEndPos != matchBlk[1]) {
282
                            editorUI.repaintBlock(markStartPos, markEndPos);
283
                            Utilities.moveMark(doc, highlightBraceStartMark, matchBlk[0]);
284
                            Utilities.moveMark(doc, highlightBraceEndMark, matchBlk[1]);
285
                            editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
286
                        } else { // on the same position
287
                            if (!braceMarksValid) { // was not valid, must repaint
240
                                editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
288
                                editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
241
                            } else { // on the same position
242
                                if (!braceMarksValid) { // was not valid, must repaint
243
                                    editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
244
                                }
245
                            }
289
                            }
246
                        } else { // highlight mark is null
247
                            highlightBraceStartMark = new MarkFactory.DrawMark(
248
                                                       HIGHLIGHT_BRACE_LAYER_NAME, editorUI);
249
                            highlightBraceEndMark = new MarkFactory.DrawMark(
250
                                                       HIGHLIGHT_BRACE_LAYER_NAME, editorUI);
251
                            highlightBraceStartMark.setActivateLayer(true);
252
                            Utilities.insertMark(doc, highlightBraceStartMark, matchBlk[0]);
253
                            Utilities.insertMark(doc, highlightBraceEndMark, matchBlk[1]);
254
                            editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
255
                        }
290
                        }
256
                        braceMarksValid = true;
291
                    } else { // highlight mark is null
257
                        madeValid = true;
292
                        highlightBraceStartMark = new MarkFactory.DrawMark(
293
                                                    HIGHLIGHT_BRACE_LAYER_NAME, editorUI);
294
                        highlightBraceEndMark = new MarkFactory.DrawMark(
295
                                                    HIGHLIGHT_BRACE_LAYER_NAME, editorUI);
296
                        highlightBraceStartMark.setActivateLayer(true);
297
                        Utilities.insertMark(doc, highlightBraceStartMark, matchBlk[0]);
298
                        Utilities.insertMark(doc, highlightBraceEndMark, matchBlk[1]);
299
                        editorUI.repaintBlock(matchBlk[0], matchBlk[1]);
258
                    }
300
                    }
301
                    braceMarksValid = true;
302
                    madeValid = true;
259
                }
303
                }
260
304
261
                if (!madeValid) {
305
                if (!madeValid) {
(-)libsrc/org/netbeans/editor/ext/ExtKit.java (-8 / +19 lines)
Lines 578-591 Link Here
578
                    BaseDocument doc = Utilities.getDocument(target);
578
                    BaseDocument doc = Utilities.getDocument(target);
579
                    int dotPos = caret.getDot();
579
                    int dotPos = caret.getDot();
580
                    ExtSyntaxSupport sup = (ExtSyntaxSupport)doc.getSyntaxSupport();
580
                    ExtSyntaxSupport sup = (ExtSyntaxSupport)doc.getSyntaxSupport();
581
                    if (dotPos > 0) {
581
                    int[] matchBlk = null;
582
                        int[] matchBlk = sup.findMatchingBlock(dotPos - 1, false);
582
                    if(caret instanceof ExtCaret) {
583
                        if (matchBlk != null) {
583
                        int how = ((ExtCaret)caret).getMatchBraceOffset();
584
                            if (select) {
584
                        if(dotPos > 0 && (how == ExtCaret.MATCH_BRACE_BEFORE
585
                                caret.moveDot(matchBlk[1]);
585
                                        || how == ExtCaret.MATCH_BRACE_EITHER)) {
586
                            } else {
586
                            matchBlk = sup.findMatchingBlock(dotPos - 1, false);
587
                                caret.setDot(matchBlk[1]);
587
                        }
588
                            }
588
                        if(matchBlk == null && (how == ExtCaret.MATCH_BRACE_AFTER
589
                                    || how == ExtCaret.MATCH_BRACE_EITHER)) {
590
                            matchBlk = sup.findMatchingBlock(dotPos, false);
591
                        }
592
                    } else if(dotPos > 0) {
593
                        matchBlk = sup.findMatchingBlock(dotPos - 1, false);
594
                    }
595
                    if (matchBlk != null) {
596
                        if (select) {
597
                            caret.moveDot(matchBlk[1]);
598
                        } else {
599
                            caret.setDot(matchBlk[1]);
589
                        }
600
                        }
590
                    }
601
                    }
591
                } catch (BadLocationException e) {
602
                } catch (BadLocationException e) {

Return to bug 95126