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 226368
Collapse All | Expand All

(-)a/editor.lib/src/org/netbeans/editor/BaseCaret.java (-30 / +36 lines)
Lines 78-83 Link Here
78
import java.io.IOException;
78
import java.io.IOException;
79
import java.util.ArrayList;
79
import java.util.ArrayList;
80
import java.util.List;
80
import java.util.List;
81
import java.util.concurrent.Callable;
81
import java.util.logging.Level;
82
import java.util.logging.Level;
82
import java.util.logging.Logger;
83
import java.util.logging.Logger;
83
import java.util.prefs.PreferenceChangeEvent;
84
import java.util.prefs.PreferenceChangeEvent;
Lines 1510-1546 Link Here
1510
                    // Disable drag which would otherwise occur when mouse would be over text
1506
                    // Disable drag which would otherwise occur when mouse would be over text
1511
                    c.setDragEnabled(false);
1507
                    c.setDragEnabled(false);
1512
                    // Check possible fold expansion
1508
                    // Check possible fold expansion
1513
                    FoldHierarchy hierarchy = FoldHierarchy.get(c);
1509
                    try {
1514
                    Document doc = c.getDocument();
1510
                        // hack, to get knowledge of possible expansion. Editor depends on Folding, so it's not really possible
1515
                    if (doc instanceof AbstractDocument) {
1511
                        // to have Folding depend on BaseCaret (= a cycle). If BaseCaret moves to editor.lib2, this contract
1516
                        AbstractDocument adoc = (AbstractDocument) doc;
1512
                        // can be formalized as an interface.
1517
                        adoc.readLock();
1513
                        Callable<Boolean> cc = (Callable<Boolean>)c.getClientProperty("org.netbeans.api.fold.expander");
1518
                        try {
1514
                        if (cc == null || !cc.call()) {
1519
                            hierarchy.lock();
1515
                            if (selectWordAction == null) {
1520
                            try {
1516
                                selectWordAction = ((BaseKit) c.getUI().getEditorKit(
1521
                                Fold collapsed = FoldUtilities.findCollapsedFold(
1517
                                        c)).getActionByName(BaseKit.selectWordAction);
1522
                                        hierarchy, offset, offset);
1523
                                if (collapsed != null && collapsed.getStartOffset() <= offset
1524
                                        && collapsed.getEndOffset() >= offset) {
1525
                                    hierarchy.expand(collapsed);
1526
                                } else {
1527
                                    if (selectWordAction == null) {
1528
                                        selectWordAction = ((BaseKit) c.getUI().getEditorKit(
1529
                                                c)).getActionByName(BaseKit.selectWordAction);
1530
                                    }
1531
                                    if (selectWordAction != null) {
1532
                                        selectWordAction.actionPerformed(null);
1533
                                    }
1534
                                    // Select word action selects forward i.e. dot > mark
1535
                                    minSelectionStartOffset = getMark();
1536
                                    minSelectionEndOffset = getDot();
1537
                                }
1538
                            } finally {
1539
                                hierarchy.unlock();
1540
                            }
1518
                            }
1541
                        } finally {
1519
                            if (selectWordAction != null) {
1542
                            adoc.readUnlock();
1520
                                selectWordAction.actionPerformed(null);
1521
                            }
1522
                            // Select word action selects forward i.e. dot > mark
1523
                            minSelectionStartOffset = getMark();
1524
                            minSelectionEndOffset = getDot();
1543
                        }
1525
                        }
1526
                    } catch (Exception ex) {
1527
                        Exceptions.printStackTrace(ex);
1544
                    }
1528
                    }
1545
                    break;
1529
                    break;
1546
                    
1530
                    
Lines 2304-2308 Link Here
2304
        DRAG_SELECTION  // Drag is being done (text selection existed at the mouse press)
2238
        DRAG_SELECTION  // Drag is being done (text selection existed at the mouse press)
2305
        
2239
        
2306
    }
2240
    }
2307
    
2241
2242
    /**
2243
     * Refreshes caret display on the screen.
2244
     * Some height or view changes may result in the caret going off the screen. In some cases, this is not desirable,
2245
     * as the user's work may be interrupted by e.g. an automatic refresh. This method repositions the view so the
2246
     * caret remains visible.
2247
     * <p/>
2248
     * The method has two modes: it can reposition the view just if it originally displayed the caret and the caret became
2249
     * invisible, and it can scroll the caret into view unconditionally.
2250
     * @param retainInView true to scroll only if the caret was visible. False to refresh regardless of visibility.
2251
     */
2252
    public void refresh(boolean retainInView) {
2253
        Rectangle b = caretBounds;
2254
        updateAfterFoldHierarchyChange = b != null;
2255
        boolean wasInView = b != null && component.getVisibleRect().intersects(b);
2256
        update(!retainInView || wasInView);
2257
    }
2258
2308
}
2259
}
(-)a/editor.lib/apichanges.xml (+15 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        <change id="caret-refresh">
111
            <summary>Allow to refresh editor view so that caret is visible</summary>
112
            <version major="3" minor="37"/>
113
            <date day="26" month="2" year="2013"/>
114
            <author login="sdedic"/>
115
            <compatibility binary="compatible" source="compatible" semantic="compatible" addition="yes"/>
116
            <description>
117
                <p>
118
                    The method helps to ensure that the caret, if it was originally visible on the screen,
119
                    will remain visible after some view hierarchy change (i.e. define a new fold).
120
                </p>
121
            </description>
122
            <issue number="226368"/>
123
            <class name="BaseCaret" package="org.netbeans.editor"/>
124
        </change>
110
        <change id="moving-find">
125
        <change id="moving-find">
111
            <summary>Moving find implementations to module editor.search</summary>
126
            <summary>Moving find implementations to module editor.search</summary>
112
            <version major="3" minor="36"/>
127
            <version major="3" minor="36"/>
(-)a/editor.lib/arch.xml (+9 lines)
Lines 632-637 Link Here
632
        To specify modifiers for which the hyperlinking should be enabled, or to switch the hyperlinking off.
632
        To specify modifiers for which the hyperlinking should be enabled, or to switch the hyperlinking off.
633
        Valid values are "[CSMA]+" (to specify combination of modifiers) or "off" (to switch hyperlinking off).
633
        Valid values are "[CSMA]+" (to specify combination of modifiers) or "off" (to switch hyperlinking off).
634
    </api>
634
    </api>
635
    <api type="export" group="clientproperty" name="org.netbeans.api.fold.expander" category="friend">
636
        The client property must be defined on JTextComponent managed by the NetBeans editor.
637
        <p/>
638
        Mouse gestures require to determine whether the point at caret is folded or not. Plain text is then selected.
639
        The client property org.netbeans.api.fold.expander (if defined) should contains a Callable&lt;Boolean> that
640
        returns false, if the point is a plaintext, true otherwise. Fold expansion should be handled by the Callable.
641
        <p/>
642
        editor.fold module uses this client property to hook into BaseCaret processing.
643
    </api>
635
</answer>
644
</answer>
636
645
637
646
(-)a/editor.lib/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
42
43
javac.compilerargs=-Xlint:unchecked
43
javac.compilerargs=-Xlint:unchecked
44
javac.source=1.6
44
javac.source=1.6
45
spec.version.base=3.36.0
45
spec.version.base=3.37.0
46
is.autoload=true
46
is.autoload=true
47
47
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml

Return to bug 226368