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

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

Introduction

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

Prototype

@Override
    public void insertData(int offset, String data) 

Source Link

Usage

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

License:Apache License

/**
 * @see RawDocument#insertData(Object, int, String)
 *//*w w w . j ava 2  s  .  co m*/
void insertData(int offset, String arg, boolean affectImpl) {
    String data = getData();
    setContentData(data.substring(0, offset) + arg + data.substring(offset, data.length()));

    if (affectImpl) {
        // NOTE(user): There is an issue here. When findNodeletWihOffset causes a
        // repair, the data may get inserted twice. The repairer may set the DOM
        // node to reflect the updated content data (which already has the data
        // inseretd). Then, when insertData is called, the data is inserted again.
        findNodeletWithOffset(offset, nodeletOffsetOutput, getRepairer());
        Text nodelet = nodeletOffsetOutput.getNode().<Text>cast();
        int nodeletOffset = nodeletOffsetOutput.getOffset();
        nodelet.insertData(nodeletOffset, arg);
        getExtendedContext().editing().textNodeletAffected(nodelet, nodeletOffset, arg.length(),
                TextNodeChangeType.DATA);
    }
}

From source file:org.waveprotocol.wave.client.editor.testing.FakeUser.java

License:Apache License

@SuppressWarnings("unchecked") // NOTE(zdwang): This is for (Point<Node>) action[1]
public void run(TypingExtractor extractor, Object... actions) throws HtmlMissing, HtmlInserted {
    for (Object a : actions) {
        Object[] action = (Object[]) a;
        Point<Node> sel = getSelectionStart();
        Text txt = sel == null ? null : sel.getContainer().<Text>cast();
        Action type = (Action) action[0];
        switch (type) {
        case MOVE:
            //extractor.flush();
            setCaret((Point<Node>) action[1]);
            break;
        case TYPE:
            String typed = (String) action[1];
            extractor.somethingHappened(getSelectionStart());
            if (sel.isInTextNode()) {
                txt.insertData(sel.getTextOffset(), (String) action[1]);
                moveCaret(((String) action[1]).length());
            } else {
                txt = Document.get().createTextNode(typed);
                sel.getContainer().insertBefore(txt, sel.getNodeAfter());
                setCaret(Point.inText((Node) txt, typed.length()));
            }/*from  www .  j  a  v  a 2 s.com*/
            break;
        case BACKSPACE:
        case DELETE:
            extractor.somethingHappened(getSelectionStart());
            int amount = (Integer) action[1];
            if (type == Action.BACKSPACE) {
                moveCaret(-amount);
            }
            deleteText(amount);
            break;
        case SPLIT:
            sel.getContainer().<Text>cast().splitText(sel.getTextOffset());
            moveCaret(0);
            break;
        }
    }
}