This fixes the DefaultCaret to only adjust the visibility when necessary
(== caret visible and location mappable).
This fixes the stupid upwards-scrolling when clicking on hyperlinks.
This is a fix for a pretty serious bug which can popup in all kinds of
text components and potentially bork caret movement. Mark can you please
include that in the release?
2006-12-06 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/text/DefaultCaret.java
(appear): Adjust visibility here.
(setDotImpl): Don't adjust visibility here.
(moveDotImpl): Don't adjust visibility here.
/Roman
Index: javax/swing/text/DefaultCaret.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultCaret.java,v
retrieving revision 1.45
diff -u -1 -5 -r1.45 DefaultCaret.java
--- javax/swing/text/DefaultCaret.java 7 Aug 2006 11:16:11 -0000 1.45
+++ javax/swing/text/DefaultCaret.java 7 Dec 2006 13:21:03 -0000
@@ -1063,32 +1063,30 @@
moveDotImpl(dot);
}
void moveDotImpl(int dot)
{
if (dot >= 0)
{
Document doc = textComponent.getDocument();
if (doc != null)
this.dot = Math.min(dot, doc.getLength());
this.dot = Math.max(this.dot, 0);
handleHighlight();
appear();
-
- adjustVisibility(this);
}
}
/**
* Sets the current position of this <code>Caret</code> within the
* <code>Document</code>. This also sets the <code>mark</code> to the new
* location.
*
* <p>If the underlying text component has a [EMAIL PROTECTED] NavigationFilter}
* installed the caret will call the corresponding method of that object.</p>
*
* @param dot
* the new position to be set
* @see #moveDot(int)
*/
@@ -1102,32 +1100,30 @@
}
void setDotImpl(int dot)
{
if (dot >= 0)
{
Document doc = textComponent.getDocument();
if (doc != null)
this.dot = Math.min(dot, doc.getLength());
this.dot = Math.max(this.dot, 0);
this.mark = this.dot;
clearHighlight();
appear();
-
- adjustVisibility(this);
}
}
/**
* Show the caret (may be hidden due blinking) and adjust the timer not to
* hide it (possibly immediately).
*
* @author Audrius Meskauskas ([EMAIL PROTECTED])
*/
void appear()
{
// All machinery is only required if the carret is blinking.
if (blinkListener != null)
{
blinkListener.ignoreNextEvent = true;
@@ -1142,31 +1138,36 @@
Rectangle area = null;
int dot = getDot();
try
{
area = getComponent().modelToView(dot);
}
catch (BadLocationException e)
{
// Let's ignore that. This shouldn't really occur. But if it
// does (it seems that this happens when the model is mutating),
// it causes no real damage. Uncomment this for debugging.
// e.printStackTrace();
}
if (area != null)
- damage(area);
+ {
+ adjustVisibility(area);
+ if (getMagicCaretPosition() == null)
+ setMagicCaretPosition(new Point(area.x, area.y));
+ damage(area);
+ }
}
repaint();
}
/**
* Returns <code>true</code> if this <code>Caret</code> is blinking,
* and <code>false</code> if not. The returned value is independent of
* the visiblity of this <code>Caret</code> as returned by [EMAIL PROTECTED] #isVisible()}.
*
* @return <code>true</code> if this <code>Caret</code> is blinking,
* and <code>false</code> if not.
* @see #isVisible()
* @since 1.5
*/
public boolean isActive()