aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/javax/swing/text
diff options
context:
space:
mode:
authordmarkov <none@none>2014-10-10 13:11:08 +0400
committerdmarkov <none@none>2014-10-10 13:11:08 +0400
commit09e57922459dfffc8f09d4a1eea3a41a5f8ee22c (patch)
tree0cebc21a7d55af0827571dd8e15449fb66ce5982 /src/share/classes/javax/swing/text
parent27f6a441fde4396f09f0afba9b352ae042e26b46 (diff)
8058120: Rendering / caret errors with HTMLDocument
Reviewed-by: alexp, alexsch
Diffstat (limited to 'src/share/classes/javax/swing/text')
-rw-r--r--src/share/classes/javax/swing/text/html/HTMLDocument.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/share/classes/javax/swing/text/html/HTMLDocument.java b/src/share/classes/javax/swing/text/html/HTMLDocument.java
index 04a165d80..fd994e546 100644
--- a/src/share/classes/javax/swing/text/html/HTMLDocument.java
+++ b/src/share/classes/javax/swing/text/html/HTMLDocument.java
@@ -1376,8 +1376,13 @@ public class HTMLDocument extends DefaultStyledDocument {
Element parent = elem.getParentElement();
if (parent != null) {
+ // If we are going to insert the string into the body
+ // section, it is necessary to set the corrsponding flag.
+ if (HTML.Tag.BODY.name.equals(parent.getName())) {
+ insertInBody = true;
+ }
int offset = elem.getEndOffset();
- if (offset > getLength()) {
+ if (offset > (getLength() + 1)) {
offset--;
}
else if (elem.isLeaf() && getText(offset - 1, 1).
@@ -1385,6 +1390,10 @@ public class HTMLDocument extends DefaultStyledDocument {
offset--;
}
insertHTML(parent, offset, htmlText, false);
+ // Cleanup the flag, if any.
+ if (insertInBody) {
+ insertInBody = false;
+ }
}
}
}
@@ -1823,6 +1832,11 @@ public class HTMLDocument extends DefaultStyledDocument {
private static char[] NEWLINE;
/**
+ * Indicates that direct insertion to body section takes place.
+ */
+ private boolean insertInBody = false;
+
+ /**
* I18N property key.
*
* @see AbstractDocument#I18NProperty
@@ -2571,7 +2585,9 @@ public class HTMLDocument extends DefaultStyledDocument {
// Assume content should be added.
foundInsertTag(false);
foundInsertTag = true;
- inParagraph = impliedP = true;
+ // If content is added directly to the body, it should
+ // be wrapped by p-implied.
+ inParagraph = impliedP = !insertInBody;
}
if (data.length >= 1) {
addContent(data, 0, data.length);