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

The following examples show how to use com.google.gwt.dom.client.Text. 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: EditorEventHandler.java    From swellrt with Apache License 2.0 6 votes vote down vote up
void checkForWebkitEndOfLinkHack(SignalEvent signal) {
  // If it's inserting text
  if (DomHelper.isTextNode(signal.getTarget()) &&
      (signal.getType().equals(BrowserEvents.DOMCharacterDataModified) ||
       signal.getType().equals(BrowserEvents.DOMNodeInserted))) {

    Text textNode = signal.getTarget().cast();
    if (textNode.getLength() > 0) {
      Node e = textNode.getPreviousSibling();
      if (e != null && !DomHelper.isTextNode(e)
          && e.<Element>cast().getTagName().toLowerCase().equals("a")) {

        FocusedPointRange<Node> selection =  editorInteractor.getHtmlSelection();
        if (selection.isCollapsed() && selection.getFocus().getTextOffset() == 0) {
          editorInteractor.noteWebkitEndOfLinkHackOccurred(textNode);
        }
      }
    }
  }
}
 
Example #2
Source File: FakeUser.java    From swellrt with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: ContentTextNodeGwtTest.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
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 vote down vote up
/**
 * 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: EditorEventHandlerGwtTest.java    From swellrt with Apache License 2.0 6 votes vote down vote up
public void testDeleteWithRangeSelectedDeletesRange() {
  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(
      new FocusedContentRange(start, end));
  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  EditorEventHandler handler = createEditorEventHandler(interactor, subHandler);

  interactor.call(FakeEditorInteractor.DELETE_RANGE).nOf(1).withArgs(
      start, end, false).returns(start);

  handler.handleEvent(fakeEvent);
  interactor.checkExpectations();
}
 
Example #6
Source File: ContentTextNode.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #7
Source File: ContentTextNode.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Same as {@link #findNodeletWithOffset(int, HtmlPoint)}, but does not do
 * a consistency check. Instead it accepts the impl nodelet of the next
 * wrapper (or null) and assumes everthing is consistent.
 */
public void findNodeletWithOffset(int offset, HtmlPoint output, Node nextImpl) {
  HtmlView filteredHtml = getFilteredHtmlView();

  int sum = 0;
  int prevSum;
  for (Text nodelet = getImplNodelet(); nodelet != nextImpl;
      nodelet = filteredHtml.getNextSibling(nodelet).cast()) {
    prevSum = sum;
    sum += nodelet.getLength();
    if (sum >= offset) {
      output.setNode(nodelet);
      output.setOffset(offset - prevSum);
      return;
    }
  }

  output.setNode(null);
}
 
Example #8
Source File: AbstractDropdown.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void resetInner() {
	this.anchor.getElement().removeAllChildren();
	if (this.iconType != null) {
		Icon icon = new Icon();
		icon.setType(this.iconType);

		this.anchor.getElement().appendChild(icon.getElement());
	}
	if (this.label != null) {
		Text textElem = Document.get().createTextNode(this.label);
		this.anchor.getElement().appendChild(textElem);
	}
	Text spaceElem = Document.get().createTextNode(" ");
	this.anchor.getElement().appendChild(spaceElem);
	this.anchor.getElement().appendChild(this.caret);
}
 
Example #9
Source File: EditorEventHandlerGwtTest.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
public void testDeleteWithRangeSelectedDeletesRange() {
  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(
      new FocusedContentRange(start, end));
  EditorEventsSubHandler subHandler = new FakeEditorEventsSubHandler();
  EditorEventHandler handler = createEditorEventHandler(interactor, subHandler);

  interactor.call(FakeEditorInteractor.DELETE_RANGE).nOf(1).withArgs(
      start, end, false).returns(start);

  handler.handleEvent(fakeEvent);
  interactor.checkExpectations();
}
 
Example #10
Source File: OutputBoolean.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void resetInner() {
	if (this.elementExists()) {
		Element element = this.getElement();
		element.removeAllChildren();
		boolean rendervalue = Boolean.TRUE.equals(this.getValue());
		if (this.outputType != RenderType.TEXT) {
			Icon icon = rendervalue ? this.trueIcon : this.falseIcon;
			if (icon != null) {
				element.appendChild(icon.getElement());
			}
		}
		if (this.outputType != RenderType.ICON) {
			Text textElem = Document.get().createTextNode(rendervalue ? this.trueLabel : this.falseLabel);
			element.appendChild(textElem);
		}
	}
}
 
Example #11
Source File: CodeLineImpl.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void redraw() {
	this.getElement().removeAllChildren();
	for (Token<?> token : this.tokenList) {
		if (token.getContent() != null && token.getContent() instanceof CssRendererTokenContent
			&& ((CssRendererTokenContent) token.getContent()).getCssStyle() != null) {
			SpanElement spanElement = Document.get().createSpanElement();
			spanElement.addClassName(((CssRendererTokenContent) token.getContent()).getCssStyle());
			spanElement.setInnerText(token.getText());
			this.getElement().appendChild(spanElement);
		} else {
			Text textElement = Document.get().createTextNode(token.getText());
			this.getElement().appendChild(textElement);
		}
	}
}
 
Example #12
Source File: FakeUser.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #13
Source File: TypingExtractor.java    From swellrt with Apache License 2.0 6 votes vote down vote up
private boolean isPartOfThisState(Point<Node> point) {

      checkRangeIsValid();

      Text node = point.isInTextNode()
        ? point.getContainer().<Text>cast()
        : null;

      if (node == null) {
        // If we're not in a text node - i.e. we just started typing
        // either in an empty element, or between elements.
        if (htmlRange.getNodeAfter() == point.getNodeAfter()
            && htmlRange.getContainer() == point.getContainer()) {
          return true;
        } else if (point.getNodeAfter() == null) {
          return false;
        } else {
          return partOfMutatingRange(point.getNodeAfter());
        }
      }

      // The first check is redundant but speeds up the general case
      return node == lastTextNode || partOfMutatingRange(node);
    }
 
Example #14
Source File: DomMutationReverter.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Deals with a dom mutation event, deciding if it is damaging or not.
 *
 * WARNING: This method should NOT be called for mutation events that are a
 * result of programmatic changes - only for changes that the browser did by
 * itself and we need to investigate. Doing otherwise will result in
 * programmatic changes being reverted!
 *
 * @param event a dom mutation event
 */
public void handleMutationEvent(SignalEvent event) {
  // TODO(user): Do we care about other types of events?
  if (event.getType().equals("DOMNodeRemoved")) {
    Node target = event.getTarget();
    boolean ignorableWhenEmpty = DomHelper.isTextNode(target)
        || !NodeManager.hasBackReference(target.<Element>cast());
    if (ignorableWhenEmpty && entries.isEmpty()) {
      // If it's a text node, or a non-backreferenced element,
      // and we don't already have entries, then we just ignore it as regular typing. Ok.
    } else {

      EditorStaticDeps.logger.trace().log("REVERT REMOVAL: " + (DomHelper.isTextNode(target)
          ? target.<Text>cast().getData() : target.<Element>cast().getTagName()));

      addEntry(new RemovalEntry(target, target.getParentElement(), target.getNextSibling(),
          ignorableWhenEmpty));
    }
  }
}
 
Example #15
Source File: ContentTextNode.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * @see RawDocument#insertData(Object, int, String)
 */
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);
  }
}
 
Example #16
Source File: ContentTextNode.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Same as {@link #findNodeletWithOffset(int, HtmlPoint)}, but does not do
 * a consistency check. Instead it accepts the impl nodelet of the next
 * wrapper (or null) and assumes everthing is consistent.
 */
public void findNodeletWithOffset(int offset, HtmlPoint output, Node nextImpl) {
  HtmlView filteredHtml = getFilteredHtmlView();

  int sum = 0;
  int prevSum;
  for (Text nodelet = getImplNodelet(); nodelet != nextImpl;
      nodelet = filteredHtml.getNextSibling(nodelet).cast()) {
    prevSum = sum;
    sum += nodelet.getLength();
    if (sum >= offset) {
      output.setNode(nodelet);
      output.setOffset(offset - prevSum);
      return;
    }
  }

  output.setNode(null);
}
 
Example #17
Source File: SelectionMaintainer.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
private boolean matchesSelectionTextNodes(Text nodelet, int affectedAfterOffset) {
  if (savedSelection == null) {
    return false;
  }
  if (savedSelection.isOrdered()) {
    if (nodelet == savedSelectionAnchorTextNodelet) {
      return savedSelectionAnchorOffset > affectedAfterOffset;
    } else if (nodelet == savedSelectionFocusTextNodelet) {
      return true;
    }
  } else {
    // The inverse of the above
    if (nodelet == savedSelectionFocusTextNodelet) {
      return savedSelectionFocusOffset > affectedAfterOffset;
    } else if (nodelet == savedSelectionAnchorTextNodelet) {
      return true;
    }
  }
  return false;
}
 
Example #18
Source File: EditorEventHandler.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
void checkForWebkitEndOfLinkHack(SignalEvent signal) {
  // If it's inserting text
  if (DomHelper.isTextNode(signal.getTarget()) &&
      (signal.getType().equals(BrowserEvents.DOMCharacterDataModified) ||
       signal.getType().equals(BrowserEvents.DOMNodeInserted))) {

    Text textNode = signal.getTarget().cast();
    if (textNode.getLength() > 0) {
      Node e = textNode.getPreviousSibling();
      if (e != null && !DomHelper.isTextNode(e)
          && e.<Element>cast().getTagName().toLowerCase().equals("a")) {

        FocusedPointRange<Node> selection =  editorInteractor.getHtmlSelection();
        if (selection.isCollapsed() && selection.getFocus().getTextOffset() == 0) {
          editorInteractor.noteWebkitEndOfLinkHackOccurred(textNode);
        }
      }
    }
  }
}
 
Example #19
Source File: NodeManager.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #20
Source File: NodeManager.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a nodelet to a Point of contentNode
 *
 * @param nodelet
 * @return content node point
 * @throws HtmlInserted
 * @throws HtmlMissing
 */
public Point<ContentNode> nodeletPointToWrapperPoint(Point<Node> nodelet) throws HtmlInserted,
    HtmlMissing {
  if (nodelet.isInTextNode()) {
    return textNodeToWrapperPoint(nodelet.getContainer().<Text> cast(), nodelet.getTextOffset());
  } else {
    return elementNodeToWrapperPoint(nodelet.getContainer().<Element> cast(), nodelet
        .getNodeAfter());
  }
}
 
Example #21
Source File: NodeManager.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a nodelet to a Point of contentNode
 *
 * @param nodelet
 * @return content node point
 * @throws HtmlInserted
 * @throws HtmlMissing
 */
public Point<ContentNode> nodeletPointToWrapperPoint(Point<Node> nodelet) throws HtmlInserted,
    HtmlMissing {
  if (nodelet.isInTextNode()) {
    return textNodeToWrapperPoint(nodelet.getContainer().<Text> cast(), nodelet.getTextOffset());
  } else {
    return elementNodeToWrapperPoint(nodelet.getContainer().<Element> cast(), nodelet
        .getNodeAfter());
  }
}
 
Example #22
Source File: NodeManager.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/** TODO(danilatos,user) Bring back early exit & clean up this interface */
public ContentNode findNodeWrapper(Node node, Element earlyExit)
    throws HtmlInserted, HtmlMissing {
  if (node == null) {
    return null;
  }
  if (DomHelper.isTextNode(node)) {
    return findTextWrapper(node.<Text>cast(), false);
  } else {
    return findElementWrapper(node.<Element>cast(), earlyExit);
  }
}
 
Example #23
Source File: PasteExtractor.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/** Utility for creating tokenizer based on UA. */
private RichTextTokenizer createTokenizer(Element container) {
  if (UserAgent.isFirefox()) {
    return new RichTextTokenizerImplFirefox<Node, Element, Text>(new HtmlViewImpl(container));
  } else {
    return new RichTextTokenizerImpl<Node, Element, Text>(new HtmlViewImpl(container));
  }
}
 
Example #24
Source File: NodeManagerGwtTest.java    From swellrt with Apache License 2.0 5 votes vote down vote up
protected void checkWrapper(ContentTextNode wrapper, Text nodelet, boolean attemptRepair)
    throws HtmlInserted, HtmlMissing {
  assertSame(wrapper, m.findTextWrapper(nodelet, attemptRepair));
  assertEquals(wrapper.getData(), wrapper.getImplData());
  assertSame(wrapper, m.findTextWrapper(nodelet, true));
  assertEquals(wrapper.getData(), wrapper.getImplData());
}
 
Example #25
Source File: SelectionMaintainer.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * @see LowLevelEditingConcerns#textNodeletAffected(Text, int, int, TextNodeChangeType)
 */
void textNodeletAffected(Text nodelet, int affectedAfterOffset, int insertionAmount,
    TextNodeChangeType changeType) {

  if (needToRestoreSelection == true) {
    return;
  }
  switch (changeType) {
  case DATA:
    if (!QuirksConstants.OK_SELECTION_ACROSS_TEXT_NODE_DATA_CHANGES &&
        matchesSelectionTextNodes(nodelet, affectedAfterOffset)) {
      needToRestoreSelection = true;
    } else {
      maybeUpdateNodeOffsets(nodelet, affectedAfterOffset, nodelet, insertionAmount);
    }
    return;
  case SPLIT:
    if (matchesSelectionTextNodes(nodelet, affectedAfterOffset)) {
      if (!QuirksConstants.OK_SELECTION_ACROSS_TEXT_NODE_SPLITS) {
        needToRestoreSelection = true;
      } else {
        maybeUpdateNodeOffsets(nodelet, affectedAfterOffset,
            nodelet.getNextSibling().<Text>cast(), -affectedAfterOffset);
      }
    }
    return;
  case REMOVE:
    if (!QuirksConstants.OK_SELECTION_ACROSS_NODE_REMOVALS &&
        matchesSelectionTextNodes(nodelet)) {
      needToRestoreSelection = true;
    }
    return;
  case MOVE:
  case REPLACE_DATA:
    if (matchesSelectionTextNodes(nodelet)) {
      needToRestoreSelection = true;
    }
    return;
  }
}
 
Example #26
Source File: ContentTextNode.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Splits this text node at the given offset.
 * If the offset is zero, no split occurs, and the current node is returned.
 * If the offset is equal to or greater than the length of the text node, no split
 * occurs, and null is returned.
 *
 * @see RawDocument#splitText(Object, int)
 */
ContentTextNode splitText(int offset, boolean affectImpl) {
  if (offset == 0) {
    return this;
  } else if (offset >= getLength()) {
    return null;
  }

  Text nodelet = null;

  if (affectImpl) {
    nodelet = implSplitText(offset);
  } else {
    nodelet = Document.get().createTextNode("");
  }

  String first = getData().substring(0, offset);
  String second = getData().substring(offset);

  ContentTextNode sibling = new ContentTextNode(second, nodelet, getExtendedContext());
  setContentData(first);

  // Always false for affecting the impl, as it's already been done
  getParentElement().insertBefore(sibling, getNextSibling(), false);

  return sibling;
}
 
Example #27
Source File: ContentTextNode.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * @see RawDocument#deleteData(Object, int, int)
 */
void deleteData(int offset, int count, boolean affectImpl) {
  String data = getData();

  setContentData(
      data.substring(0, offset) +
      data.substring(offset + count, data.length()));

  if (affectImpl) {
    if (isImplAttached()) {
      findNodeletWithOffset(offset, nodeletOffsetOutput, getRepairer());
      Text nodelet = nodeletOffsetOutput.getNode().cast();
      int subOffset = nodeletOffsetOutput.getOffset();

      if (nodelet.getLength() - subOffset >= count) {
        // Handle the special case where the delete is in a single text nodelet
        // carefully, to avoid splitting it
        nodelet.deleteData(subOffset, count);
        getExtendedContext().editing().textNodeletAffected(
            nodelet, subOffset, -count, TextNodeChangeType.DATA);
      } else {
        // General case
        Node toExcl = implSplitText(offset + count);
        Node fromIncl = implSplitText(offset);

        HtmlView filteredHtml = getFilteredHtmlView();
        for (Node node = fromIncl; node != toExcl && node != null;) {
          Node next = filteredHtml.getNextSibling(node);
          node.removeFromParent();
          node = next;
        }
      }
    } else {
      // TODO(user): have these assertion failure fixed (b/2129931)
      // assert getImplNodelet().getLength() == getLength() :
      //    "text node's html impl not normalised while not attached to html dom";
      getImplNodelet().deleteData(offset, count);
    }
  }
}
 
Example #28
Source File: SelectionMaintainer.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private void maybeUpdateNodeOffsets(Text nodelet, int affectedAfterOffset,
    Text newNodelet, int offsetDifference) {
  if (nodelet == savedSelectionAnchorTextNodelet &&
      savedSelectionAnchorOffset > affectedAfterOffset) {
    savedSelectionAnchorOffset += offsetDifference;
    savedSelectionAnchorTextNodelet = newNodelet;
  }
  if (nodelet == savedSelectionFocusTextNodelet &&
      savedSelectionFocusOffset > affectedAfterOffset) {
    savedSelectionFocusOffset += offsetDifference;
    savedSelectionFocusTextNodelet = newNodelet;
  }
}
 
Example #29
Source File: DomMutationReverter.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public void cleanup() {
  if (removeAfter) {
    EditorStaticDeps.logger.trace().log("REVERT CLEANUP: " + (DomHelper.isTextNode(removedNode)
        ? removedNode.<Text>cast().getData() : removedNode.<Element>cast().getTagName()));
    removedNode.removeFromParent();
  }
}
 
Example #30
Source File: ContentTextNode.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private static int sumTextNodesLength(Text fromIncl, Node toExcl, HtmlView filteredHtml) {
  int length = 0;
  for (Text n = fromIncl; n != toExcl && n != null;
      n = filteredHtml.getNextSibling(n).cast()) {
    length += n.getLength();
  }

  return length;
}