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 2017/02/17 18:34:30 UTC
svn commit: r1783447 -
/pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java
Author: rwhitcomb
Date: Fri Feb 17 18:34:30 2017
New Revision: 1783447
URL: http://svn.apache.org/viewvc?rev=1783447&view=rev
Log:
PIVOT-992: Change the "getSelectedText" method of TextPane to just use the equivalent
call to "getText(start, finish)" instead of doing a "getSelectedRange()" and serializing
that. The results will be different in that if the selection doesn't actually encompass
an end of line, then the result will not contain a spurious newline.
The difference affects find/replace operations (for instance) that would be calling
"getSelectedText" and doing a find operation on a piece of text that doesn't actually
appear in the document (like "abc\n").
I suspect that this new method is actually a bit faster than the old way, although
that probably makes little to no difference in actual use.
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=1783447&r1=1783446&r2=1783447&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TextPane.java Fri Feb 17 18:34:30 2017
@@ -1035,22 +1035,7 @@ public class TextPane extends Container
* or <tt>null</tt> if nothing is selected.
*/
public String getSelectedText() {
- String selectedText = null;
-
- if (selectionLength > 0) {
- Document selection = (Document) document.getRange(selectionStart, selectionLength);
-
- try {
- PlainTextSerializer serializer = new PlainTextSerializer();
- StringWriter writer = new StringWriter();
- serializer.writeObject(selection, writer);
- selectedText = writer.toString();
- } catch (IOException exception) {
- throw new RuntimeException(exception);
- }
- }
-
- return selectedText;
+ return selectionLength > 0 ? getText(selectionStart, selectionStart + selectionLength) : null;
}
/**