diff --git a/editor.lib/src/org/netbeans/editor/BaseCaret.java b/editor.lib/src/org/netbeans/editor/BaseCaret.java --- a/editor.lib/src/org/netbeans/editor/BaseCaret.java +++ b/editor.lib/src/org/netbeans/editor/BaseCaret.java @@ -78,6 +78,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.logging.Logger; import java.util.prefs.PreferenceChangeEvent; @@ -1510,37 +1506,25 @@ // Disable drag which would otherwise occur when mouse would be over text c.setDragEnabled(false); // Check possible fold expansion - FoldHierarchy hierarchy = FoldHierarchy.get(c); - Document doc = c.getDocument(); - if (doc instanceof AbstractDocument) { - AbstractDocument adoc = (AbstractDocument) doc; - adoc.readLock(); - try { - hierarchy.lock(); - try { - Fold collapsed = FoldUtilities.findCollapsedFold( - hierarchy, offset, offset); - if (collapsed != null && collapsed.getStartOffset() <= offset - && collapsed.getEndOffset() >= offset) { - hierarchy.expand(collapsed); - } else { - if (selectWordAction == null) { - selectWordAction = ((BaseKit) c.getUI().getEditorKit( - c)).getActionByName(BaseKit.selectWordAction); - } - if (selectWordAction != null) { - selectWordAction.actionPerformed(null); - } - // Select word action selects forward i.e. dot > mark - minSelectionStartOffset = getMark(); - minSelectionEndOffset = getDot(); - } - } finally { - hierarchy.unlock(); + try { + // hack, to get knowledge of possible expansion. Editor depends on Folding, so it's not really possible + // to have Folding depend on BaseCaret (= a cycle). If BaseCaret moves to editor.lib2, this contract + // can be formalized as an interface. + Callable cc = (Callable)c.getClientProperty("org.netbeans.api.fold.expander"); + if (cc == null || !cc.call()) { + if (selectWordAction == null) { + selectWordAction = ((BaseKit) c.getUI().getEditorKit( + c)).getActionByName(BaseKit.selectWordAction); } - } finally { - adoc.readUnlock(); + if (selectWordAction != null) { + selectWordAction.actionPerformed(null); + } + // Select word action selects forward i.e. dot > mark + minSelectionStartOffset = getMark(); + minSelectionEndOffset = getDot(); } + } catch (Exception ex) { + Exceptions.printStackTrace(ex); } break; @@ -2304,5 +2238,22 @@ DRAG_SELECTION // Drag is being done (text selection existed at the mouse press) } - + + /** + * Refreshes caret display on the screen. + * Some height or view changes may result in the caret going off the screen. In some cases, this is not desirable, + * as the user's work may be interrupted by e.g. an automatic refresh. This method repositions the view so the + * caret remains visible. + *

+ * The method has two modes: it can reposition the view just if it originally displayed the caret and the caret became + * invisible, and it can scroll the caret into view unconditionally. + * @param retainInView true to scroll only if the caret was visible. False to refresh regardless of visibility. + */ + public void refresh(boolean retainInView) { + Rectangle b = caretBounds; + updateAfterFoldHierarchyChange = b != null; + boolean wasInView = b != null && component.getVisibleRect().intersects(b); + update(!retainInView || wasInView); + } + } diff --git a/editor.lib/apichanges.xml b/editor.lib/apichanges.xml --- a/editor.lib/apichanges.xml +++ b/editor.lib/apichanges.xml @@ -107,6 +107,21 @@ + +

Allow to refresh editor view so that caret is visible + + + + + +

+ The method helps to ensure that the caret, if it was originally visible on the screen, + will remain visible after some view hierarchy change (i.e. define a new fold). +

+
+ + + Moving find implementations to module editor.search diff --git a/editor.lib/arch.xml b/editor.lib/arch.xml --- a/editor.lib/arch.xml +++ b/editor.lib/arch.xml @@ -632,6 +632,15 @@ To specify modifiers for which the hyperlinking should be enabled, or to switch the hyperlinking off. Valid values are "[CSMA]+" (to specify combination of modifiers) or "off" (to switch hyperlinking off). + + The client property must be defined on JTextComponent managed by the NetBeans editor. +

+ Mouse gestures require to determine whether the point at caret is folded or not. Plain text is then selected. + The client property org.netbeans.api.fold.expander (if defined) should contains a Callable<Boolean> that + returns false, if the point is a plaintext, true otherwise. Fold expansion should be handled by the Callable. +

+ editor.fold module uses this client property to hook into BaseCaret processing. + diff --git a/editor.lib/nbproject/project.properties b/editor.lib/nbproject/project.properties --- a/editor.lib/nbproject/project.properties +++ b/editor.lib/nbproject/project.properties @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.6 -spec.version.base=3.36.0 +spec.version.base=3.37.0 is.autoload=true javadoc.arch=${basedir}/arch.xml