Package com.google.gwt.dom.client

Examples of com.google.gwt.dom.client.Text


        if (level == 0 && nextSibling == null && Whitespace.isWhite(chars)) {
            return; // no action for top-level whitespace
        }

        try {
          Text text = document.createTextNode(chars.toString());
          if (nextSibling != null && level == 0) {
              currentNode.insertBefore(text, nextSibling);
          } else {
              currentNode.appendChild(text);
          }
View Full Code Here


    FakeEditorEvent fakeEvent = FakeEditorEvent.create(KeySignalType.DELETE, KeyCodes.KEY_LEFT);

    //Event event = Document.get().createKeyPressEvent(
    //    false, false, false, false, KeyCodes.KEY_BACKSPACE, 0).cast();

    Text input = Document.get().createTextNode("ABCDE");
    ContentNode node = new ContentTextNode(input, null);

    final Point<ContentNode> start = Point.inText(node, 1);
    final Point<ContentNode> end = Point.inText(node, 4);
    FakeEditorInteractor interactor = setupFakeEditorInteractor(
View Full Code Here

    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));
  }
View Full Code Here

    c = dom.debugGetRawDocument();
    ContentElement root = c.getDocumentElement();

    ContentTextNode t1 = c.createTextNode("hello", root, null);
    ContentTextNode t2 = c.createTextNode("blah", root, null);
    Text txt1 = t1.getImplNodelet();
    Text txt2 = t2.getImplNodelet();

    txt1.removeFromParent();

    try {
      t1.getImplData();
      fail("Did not throw HtmlMissing exception");
    } catch (HtmlMissing e) {
      assertEquals(t1, e.getBrokenNode());
      assertEquals(root.getImplNodelet(), e.getNode());
    }

    txt2.getParentNode().insertBefore(txt1, txt2);
    txt2.removeFromParent();

    try {
      t1.getImplData();
      fail("Did not throw HtmlMissing exception");
    } catch (HtmlMissing e) {
      assertEquals(t2, e.getBrokenNode());
      assertEquals(root.getImplNodelet(), e.getNode());
    }

    Text txt1b = txt1.splitText(2);
    try {
      t1.getImplData();
      fail("Did not throw HtmlMissing exception");
    } catch (HtmlMissing e) {
      assertEquals(t2, e.getBrokenNode());
      assertEquals(root.getImplNodelet(), e.getNode());
    }

    txt1b.getParentNode().insertAfter(t2.getImplNodelet(), txt1b);
    try {
      assertEquals("hello", t1.getImplData());
    } catch (HtmlMissing e) {
      fail(e.getMessage());
      e.printStackTrace();
View Full Code Here

    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);
View Full Code Here

    // 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) {
View Full Code Here

    // or null if no such element
    Node nodeletBeforeTextNodes;
    ContentNode wrapperBeforeTextNodes;

    // Our cursors
    Text current = target;
    ContentNode possibleOwnerNode;

    // Go leftwards to find the start of the text nodelet sequence
    for (nodeletBeforeTextNodes = filteredHtml.getPreviousSibling(target);
         nodeletBeforeTextNodes != null;
         nodeletBeforeTextNodes = filteredHtml.getPreviousSibling(nodeletBeforeTextNodes)) {
      Text maybeText = filteredHtml.asText(nodeletBeforeTextNodes);
      if (maybeText == null) {
        break;
      }
      current = maybeText;
    }
View Full Code Here

    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);
  }
View Full Code Here

  @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()));
View Full Code Here

    }
  }

  private void deleteText(int amount) {
    Point<Node> sel = getSelectionStart();
    Text txt = sel == null ? null : sel.getContainer().<Text>cast();
    int startIndex = sel.getTextOffset(), len;
    while (amount > 0) {
      if (txt == null || !DomHelper.isTextNode(txt)) {
        throw new RuntimeException("Action ran off end of text node");
      }
      String data = txt.getData();
      int remainingInNode = data.length() - startIndex;
      if (remainingInNode >= amount) {
        len = amount;
      } else {
        len = remainingInNode;
      }
      txt.setData(data.substring(0, startIndex) + data.substring(startIndex + len));
      amount -= len;
      startIndex = 0;
      txt = htmlView.getNextSibling(txt).cast();
    }
    moveCaret(0);
View Full Code Here

TOP

Related Classes of com.google.gwt.dom.client.Text

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.