You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2018/01/30 16:18:23 UTC
svn commit: r1822661 -
/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java
Author: rwhitcomb
Date: Tue Jan 30 16:18:23 2018
New Revision: 1822661
URL: http://svn.apache.org/viewvc?rev=1822661&view=rev
Log:
PIVOT-1021: Fix a problem with the updated selection after undo
at the end of the document.
Modified:
pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java?rev=1822661&r1=1822660&r2=1822661&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java Tue Jan 30 16:18:23 2018
@@ -131,7 +131,7 @@ public class TextPane extends Container
@Override
public void undo() {
node.removeRange(offset, characterCount);
- setSelection(offset, 0);
+ changeSelection(offset);
}
}
@@ -149,10 +149,10 @@ public class TextPane extends Container
@Override
public void undo() {
if (offset != selectionStart) {
- setSelection(offset, 0);
+ changeSelection(offset);
}
insert(removedChars.toString());
- setSelection(offset + removedChars.length(), 0);
+ changeSelection(offset + removedChars.length());
}
}
@@ -1037,6 +1037,27 @@ public class TextPane extends Container
}
/**
+ * Change the selection to the given location (and length 0),
+ * with checks to make sure the selection doesn't go out of bounds.
+ * <p> Meant to be called from {@link #undo} (that is, internally).
+ *
+ * @param start The new selection start to check and set.
+ * @see #setSelection(int, int)
+ */
+ private void changeSelection(int start) {
+ int docCount = document.getCharacterCount();
+ if (start >= 0) {
+ if (start >= docCount) {
+ setSelection(docCount - 1, 0);
+ } else {
+ setSelection(start, 0);
+ }
+ } else {
+ setSelection(0, 0);
+ }
+ }
+
+ /**
* Selects all text.
*/
public void selectAll() {