Example usage for com.google.gwt.dom.client Text splitText

List of usage examples for com.google.gwt.dom.client Text splitText

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Text splitText.

Prototype

@Override
    public Text splitText(int offset) 

Source Link

Usage

From source file:org.waveprotocol.wave.client.editor.content.ContentTextNode.java

License:Apache License

/**
 * Splits and returns the second.//from ww w . ja va  2 s  .c  o m
 * 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;
    }
}

From source file:org.waveprotocol.wave.client.editor.impl.NodeManager.java

License:Apache License

/**
 * Converts the given point to a parent-nodeAfter point, splitting a
 * text node if necessary.//  www.jav a 2  s .  c o m
 *
 * @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);
}