Java Code Examples for com.google.gwt.dom.client.Text#splitText()
The following examples show how to use
com.google.gwt.dom.client.Text#splitText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContentTextNode.java From swellrt with Apache License 2.0 | 6 votes |
/** * Splits and returns the second. * If split point at a node boundary, doesn't split, but returns the next nodelet. */ private Text implSplitText(int offset) { findNodeletWithOffset(offset, nodeletOffsetOutput, getRepairer()); Text text = nodeletOffsetOutput.getNode().<Text>cast(); if (text.getLength() == nodeletOffsetOutput.getOffset()) { return text.getNextSibling().cast(); } else if (nodeletOffsetOutput.getOffset() == 0) { return text; } else { int nodeletOffset = nodeletOffsetOutput.getOffset(); Text ret = text.splitText(nodeletOffset); // -10000 because the number should be ignored in the splitText case, // so some large number to trigger an error if it is not ignored. getExtendedContext().editing().textNodeletAffected( text, nodeletOffset, -10000, TextNodeChangeType.SPLIT); return ret; } }
Example 2
Source File: NodeManager.java From swellrt with Apache License 2.0 | 6 votes |
/** * Converts the given point to a parent-nodeAfter point, splitting a * text node if necessary. * * @param point * @return a point at the same location, between node boundaries */ public static Point.El<Node> forceElementPoint(Point<Node> point) { Point.El<Node> elementPoint = point.asElementPoint(); if (elementPoint != null) { return elementPoint; } Element parent; Node nodeAfter; Text text = point.getContainer().cast(); parent = text.getParentElement(); int offset = point.getTextOffset(); if (offset == 0) { nodeAfter = text; } else if (offset == text.getLength()) { nodeAfter = text.getNextSibling(); } else { nodeAfter = text.splitText(offset); } return Point.inElement(parent, nodeAfter); }
Example 3
Source File: ContentTextNodeGwtTest.java From swellrt with Apache License 2.0 | 6 votes |
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)); }
Example 4
Source File: ContentTextNode.java From incubator-retired-wave with Apache License 2.0 | 6 votes |
/** * Splits and returns the second. * If split point at a node boundary, doesn't split, but returns the next nodelet. */ private Text implSplitText(int offset) { findNodeletWithOffset(offset, nodeletOffsetOutput, getRepairer()); Text text = nodeletOffsetOutput.getNode().<Text>cast(); if (text.getLength() == nodeletOffsetOutput.getOffset()) { return text.getNextSibling().cast(); } else if (nodeletOffsetOutput.getOffset() == 0) { return text; } else { int nodeletOffset = nodeletOffsetOutput.getOffset(); Text ret = text.splitText(nodeletOffset); // -10000 because the number should be ignored in the splitText case, // so some large number to trigger an error if it is not ignored. getExtendedContext().editing().textNodeletAffected( text, nodeletOffset, -10000, TextNodeChangeType.SPLIT); return ret; } }
Example 5
Source File: NodeManager.java From incubator-retired-wave with Apache License 2.0 | 6 votes |
/** * Converts the given point to a parent-nodeAfter point, splitting a * text node if necessary. * * @param point * @return a point at the same location, between node boundaries */ public static Point.El<Node> forceElementPoint(Point<Node> point) { Point.El<Node> elementPoint = point.asElementPoint(); if (elementPoint != null) { return elementPoint; } Element parent; Node nodeAfter; Text text = point.getContainer().cast(); parent = text.getParentElement(); int offset = point.getTextOffset(); if (offset == 0) { nodeAfter = text; } else if (offset == text.getLength()) { nodeAfter = text.getNextSibling(); } else { nodeAfter = text.splitText(offset); } return Point.inElement(parent, nodeAfter); }
Example 6
Source File: ContentTextNodeGwtTest.java From incubator-retired-wave with Apache License 2.0 | 6 votes |
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)); }
Example 7
Source File: NodeManagerGwtTest.java From swellrt with Apache License 2.0 | 4 votes |
public void testFindsTextNodeWrapperNormally() throws HtmlInserted, HtmlMissing { ContentDocument dom = TestEditors.createTestDocument(); c = dom.debugGetRawDocument(); ContentElement root = c.getDocumentElement(); m = dom.getContext().rendering().getNodeManager(); String s1 = "some text", s2 = "other writings", s3 = "more information"; // t1 ContentTextNode t1 = c.createTextNode(s1, root, null); Text n1 = t1.getImplNodelet(); checkWrapper(t1, n1); // b1 t1 ContentElement b1 = c.createElement("b", root, t1); checkWrapper(t1, n1); // b1 t1 b2 ContentElement b2 = c.createElement("b", root, null); checkWrapper(t1, n1); Text n1b = n1.splitText(2); checkWrapper(t1, n1b); // b1 t1 t2 b2 ContentTextNode t2 = c.createTextNode(s2, root, b2); Text n2 = t2.getImplNodelet(), n2b; checkWrapper(t1, n1); checkWrapper(t1, n1b); n2b = n2.splitText(2); checkWrapper(t2, n2); checkWrapper(t2, n2b); // t1 b2 c.removeChild(root, b1); checkWrapper(t1, n1b); checkWrapper(t2, n2b); c.removeChild(root, t2); c.removeChild(root, b2); checkWrapper(t1, n1); }
Example 8
Source File: NodeManagerGwtTest.java From incubator-retired-wave with Apache License 2.0 | 4 votes |
public void testFindsTextNodeWrapperNormally() throws HtmlInserted, HtmlMissing { ContentDocument dom = TestEditors.createTestDocument(); c = dom.debugGetRawDocument(); ContentElement root = c.getDocumentElement(); m = dom.getContext().rendering().getNodeManager(); String s1 = "some text", s2 = "other writings", s3 = "more information"; // t1 ContentTextNode t1 = c.createTextNode(s1, root, null); Text n1 = t1.getImplNodelet(); checkWrapper(t1, n1); // b1 t1 ContentElement b1 = c.createElement("b", root, t1); checkWrapper(t1, n1); // b1 t1 b2 ContentElement b2 = c.createElement("b", root, null); checkWrapper(t1, n1); Text n1b = n1.splitText(2); checkWrapper(t1, n1b); // b1 t1 t2 b2 ContentTextNode t2 = c.createTextNode(s2, root, b2); Text n2 = t2.getImplNodelet(), n2b; checkWrapper(t1, n1); checkWrapper(t1, n1b); n2b = n2.splitText(2); checkWrapper(t2, n2); checkWrapper(t2, n2b); // t1 b2 c.removeChild(root, b1); checkWrapper(t1, n1b); checkWrapper(t2, n2b); c.removeChild(root, t2); c.removeChild(root, b2); checkWrapper(t1, n1); }