Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NETBEANS-4940] Workaround for caret-on-TAB drawing issue #2482

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ide/editor.lib/apichanges.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ is the proper place.
<!-- ACTUAL CHANGES BEGIN HERE: -->

<changes>
<change id="caret-min-width">
<summary>Allow to specify minimum caret width</summary>
<version major="4" minor="17"/>
<date day="3" month="11" year="2020"/>
<author login="errael"/>
<compatibility binary="compatible" semantic="compatible" source="compatible" addition="yes" deprecation="no" deletion="no"/>
<description>
<p>
If present, JTextComponent property "CARET_MIN_WIDTH" with a value
of type IntUnaryOpertor is used by BaseCaret to override constant 2.
</p>
</description>
<class name="BaseCaret" package="org.netbeans.editor"/>
<issue number="NETBEANS-4940"/>
</change>
<change id="editor-document-split">
<summary>Document handling split</summary>
<version major="4" minor="0"/>
Expand Down
10 changes: 8 additions & 2 deletions ide/editor.lib/arch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
under the License.

-->
<!DOCTYPE api-answers PUBLIC "-//NetBeans//DTD Arch Answers//EN" "../nbbuild/antsrc/org/netbeans/nbbuild/Arch.dtd" [
<!ENTITY api-questions SYSTEM "../nbbuild/antsrc/org/netbeans/nbbuild/Arch-api-questions.xml">
<!DOCTYPE api-answers PUBLIC "-//NetBeans//DTD Arch Answers//EN" "../../nbbuild/antsrc/org/netbeans/nbbuild/Arch.dtd" [
<!ENTITY api-questions SYSTEM "../../nbbuild/antsrc/org/netbeans/nbbuild/Arch-api-questions.xml">
]>

<api-answers
Expand Down Expand Up @@ -468,6 +468,12 @@ Description of public packages:
Document property that determines the number of characters in the longest line
determined during the document loading from a reader by the editor kit.
</api>
<br/>
<api type="export" name="CARET_MIN_WIDTH" category="devel" group="property">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Category devel means: "Under development is a name for a contract that is expected to become a stable API, but that has not yet been finished. The current state serves as a proof of concept, and others are encourage to try it and comment on a dedicated mailing list. Incompatible changes may be done between releases, but should be rare, not radical and properly announced on the mailing list. "

Component client property that provides an <code>IntUnaryOperator</code>
which is invoked with a document offset and returns a minimum caret width.
This overrides a constant 2 minimum caret width.
</api>
</answer>


Expand Down
12 changes: 10 additions & 2 deletions ide/editor.lib/src/org/netbeans/editor/BaseCaret.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.function.IntUnaryOperator;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;

import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JScrollBar;
Expand All @@ -80,6 +82,7 @@
import javax.swing.text.AttributeSet;
import javax.swing.text.Position;
import javax.swing.text.StyleConstants;

import org.netbeans.api.editor.fold.FoldHierarchyEvent;
import org.netbeans.api.editor.fold.FoldHierarchyListener;
import org.netbeans.api.editor.mimelookup.MimeLookup;
Expand Down Expand Up @@ -401,9 +404,14 @@ public void run() {
c, offset, Position.Bias.Forward);
// [TODO] Temporary fix - impl should remember real bounds computed by paintCustomCaret()
if (newCaretBounds != null) {
newCaretBounds.width = Math.max(newCaretBounds.width, 2);
int minwidth = 2;
// [NETBEANS-4940] Caret drawing problems over a TAB
Object o = component.getClientProperty("CARET_MIN_WIDTH");
if(o instanceof IntUnaryOperator) {
minwidth = ((IntUnaryOperator)o).applyAsInt(offset);
}
newCaretBounds.width = Math.max(newCaretBounds.width, minwidth);
}

} catch (BadLocationException e) {
newCaretBounds = null;
Utilities.annotateLoggable(e);
Expand Down