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/09/21 00:43:33 UTC

svn commit: r1809109 - /pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java

Author: rwhitcomb
Date: Thu Sep 21 00:43:33 2017
New Revision: 1809109

URL: http://svn.apache.org/viewvc?rev=1809109&view=rev
Log:
PIVOT-1006:  Fix the calculations on when to include the composed text
at the end of a paragraph to ignore any parent TextSpan nodes if necessary.
This would be the case when the hierarchy is Paragraph->TextSpan->TextNode.

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java?rev=1809109&r1=1809108&r2=1809109&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextPaneSkinTextNodeView.java Thu Sep 21 00:43:33 2017
@@ -43,6 +43,7 @@ import org.apache.pivot.wtk.text.Element
 import org.apache.pivot.wtk.text.Paragraph;
 import org.apache.pivot.wtk.text.TextNode;
 import org.apache.pivot.wtk.text.TextNodeListener;
+import org.apache.pivot.wtk.text.TextSpan;
 
 /**
  * Text node view.
@@ -131,7 +132,14 @@ class TextPaneSkinTextNodeView extends T
         AttributedStringCharacterIterator composedText = textPane.getComposedText();
 
         Element parent = textNode.getParent();
-        String parentClass = parent == null ? "<<<null>>>" : parent.getClass().getSimpleName();
+        // The calculations below really need to know if we're at the end of the paragraph
+        // when composing text, so make sure we ignore intervening span or other nodes, but
+        // also update the offset relative to the paragraph in the process.
+        int relStart = start;
+        if (parent != null && !(parent instanceof Paragraph)) {
+            relStart += parent.getOffset();
+            parent = parent.getParent();
+        }
         int parentCount = parent == null ? 0 : parent.getCharacterCount();
 
         int selectionStart = textPane.getSelectionStart();
@@ -146,7 +154,7 @@ class TextPaneSkinTextNodeView extends T
             int composedTextLength = composedTextEnd - composedTextBegin; /* exclusive - inclusive, so no +1 needed */
             // If this text node is at the end of a paragraph, increase the span by 1 for the newline
             Span ourSpan;
-            if (parent instanceof Paragraph && charCount == parentCount - 1) {
+            if (parent instanceof Paragraph && charCount + relStart == parentCount - 1) {
                 ourSpan = new Span(documentOffset + start, documentOffset + charCount);
             } else {
                 ourSpan = new Span(documentOffset + start, documentOffset + charCount - 1);