/** * Breaks this node into two nodes at the specified <code>offset</code>, * keeping both in the tree as siblings. After being split, this node * will contain all the content up to the <code>offset</code> point. A * new node of the same type, which contains all the content at and * after the <code>offset</code> point, is returned. If the original * node had a parent node, the new node is inserted as the next sibling * of the original node. When the <code>offset</code> is equal to the * length of this node, the new node has no data. * @param offset The 16-bit unit offset at which to split, starting from * <code>0</code>. * @return The new node, of the same type as this node. * @exception DOMException * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater * than the number of 16-bit units in <code>data</code>. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. */ public final OMText splitText(int offset) throws JavaScriptException { return new OMText(((Text)ot.cast()).splitText(offset)); };
/** * Breaks this node into two nodes at the specified <code>offset</code>, * keeping both in the tree as siblings. After being split, this node * will contain all the content up to the <code>offset</code> point. A * new node of the same type, which contains all the content at and * after the <code>offset</code> point, is returned. If the original * node had a parent node, the new node is inserted as the next sibling * of the original node. When the <code>offset</code> is equal to the * length of this node, the new node has no data. * @param offset The 16-bit unit offset at which to split, starting from * <code>0</code>. * @return The new node, of the same type as this node. * @exception DOMException * INDEX_SIZE_ERR: Raised if the specified offset is negative or greater * than the number of 16-bit units in <code>data</code>. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. */ public final OMText splitText(int offset) throws JavaScriptException { return new OMText(((Text)ot.cast()).splitText(offset)); };
public void testRepairsWherePossible() throws HtmlInserted, HtmlMissing { ContentDocument dom = TestEditors.createTestDocument(); c = dom.debugGetRawDocument(); ContentElement root = c.getDocumentElement(); m = dom.getContext().rendering().getNodeManager(); // TODO(danilatos): Expand this and other test cases String s1 = "some text", s2 = "other writings", s3 = "more information"; ContentTextNode t1 = c.createTextNode(s1, root, null); Text n1 = t1.getImplNodelet(), n1b; n1b = n1.splitText(1); n1b.setData(s1); n1.removeFromParent(); try { m.findTextWrapper(n1b, false); fail("Expected exception when not repairing"); } catch (HtmlInserted e) { } catch (HtmlMissing e) { } checkWrapper(t1, n1b, true); }
public void testRepairsWherePossible() throws HtmlInserted, HtmlMissing { ContentDocument dom = TestEditors.createTestDocument(); c = dom.debugGetRawDocument(); ContentElement root = c.getDocumentElement(); m = dom.getContext().rendering().getNodeManager(); // TODO(danilatos): Expand this and other test cases String s1 = "some text", s2 = "other writings", s3 = "more information"; ContentTextNode t1 = c.createTextNode(s1, root, null); Text n1 = t1.getImplNodelet(), n1b; n1b = n1.splitText(1); n1b.setData(s1); n1.removeFromParent(); try { m.findTextWrapper(n1b, false); fail("Expected exception when not repairing"); } catch (HtmlInserted e) { } catch (HtmlMissing e) { } checkWrapper(t1, n1b, true); }
public void testImplDataSumsTextNodes() throws HtmlMissing { ContentDocument dom = TestEditors.createTestDocument(); c = dom.debugGetRawDocument(); ContentElement root = c.getDocumentElement(); ContentTextNode t1 = c.createTextNode("hello", root, null); Text txt = t1.getImplNodelet(); assertEquals("hello", t1.getImplData()); Text txt3 = Document.get().createTextNode(" there"); txt.getParentNode().insertAfter(txt3, txt); assertEquals("hello there", t1.getImplData()); Text txt2 = txt.splitText(2); assertEquals("hello there", t1.getImplData()); assertSame(txt3, txt.getNextSibling().getNextSibling()); assertTrue(t1.owns(txt) && t1.owns(txt2) && t1.owns(txt3)); ContentTextNode t2 = c.createTextNode("before", root, t1); assertEquals("before", t2.getImplData()); Text t2_2 = t2.getImplNodelet().splitText(3); assertEquals("before", t2.getImplData()); assertTrue(t2.owns(t2_2)); }
public void testImplDataSumsTextNodes() throws HtmlMissing { ContentDocument dom = TestEditors.createTestDocument(); c = dom.debugGetRawDocument(); ContentElement root = c.getDocumentElement(); ContentTextNode t1 = c.createTextNode("hello", root, null); Text txt = t1.getImplNodelet(); assertEquals("hello", t1.getImplData()); Text txt3 = Document.get().createTextNode(" there"); txt.getParentNode().insertAfter(txt3, txt); assertEquals("hello there", t1.getImplData()); Text txt2 = txt.splitText(2); assertEquals("hello there", t1.getImplData()); assertSame(txt3, txt.getNextSibling().getNextSibling()); assertTrue(t1.owns(txt) && t1.owns(txt2) && t1.owns(txt3)); ContentTextNode t2 = c.createTextNode("before", root, t1); assertEquals("before", t2.getImplData()); Text t2_2 = t2.getImplNodelet().splitText(3); assertEquals("before", t2.getImplData()); assertTrue(t2.owns(t2_2)); }
Text txt1b = txt1.splitText(2); try { t1.getImplData();
Text txt1b = txt1.splitText(2); try { t1.getImplData();
assertEquals("hello <b>there</b>", p.getImplNodelet().getInnerHTML()); Element wrapper = ca(); Node bit = t1.getImplNodelet().splitText(2); bit.getParentNode().insertBefore(wrapper, bit); wrapper.appendChild(bit);
assertEquals("hello <b>there</b>", p.getImplNodelet().getInnerHTML()); Element wrapper = ca(); Node bit = t1.getImplNodelet().splitText(2); bit.getParentNode().insertBefore(wrapper, bit); wrapper.appendChild(bit);