Permalink
Browse files

PIVOT-992: Change the "getSelectedText" method of TextPane to just us…

…e 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.


git-svn-id: https://svn.apache.org/repos/asf/pivot/trunk@1783447 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent a1d012f commit 4914fe32985c54bdaf276cf9b869340a3c025cc2 Roger Lee Whitcomb committed Feb 17, 2017
Showing with 1 addition and 16 deletions.
  1. +1 −16 wtk/src/org/apache/pivot/wtk/TextPane.java
@@ -1035,22 +1035,7 @@ public void clearSelection() {
* 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;
}
/**

0 comments on commit 4914fe3

Please sign in to comment.