Package org.eclipse.text.edits

Examples of org.eclipse.text.edits.DeleteEdit


      newEdit= new ReplaceEdit(edit.getOffset() - diff, edit.getLength(), edit.getText());
    } else if (oldEdit instanceof InsertEdit) {
      InsertEdit edit= (InsertEdit) oldEdit;
      newEdit= new InsertEdit(edit.getOffset() - diff,  edit.getText());
    } else if (oldEdit instanceof DeleteEdit) {
      DeleteEdit edit= (DeleteEdit) oldEdit;
      newEdit= new DeleteEdit(edit.getOffset() - diff,  edit.getLength());
    } else if (oldEdit instanceof MultiTextEdit) {
      newEdit= new MultiTextEdit();     
    } else {
      return null; // not supported
    }
View Full Code Here


    for (int i= 0; i < stringsToInsert.size(); i++) {
      String curr= (String) stringsToInsert.get(i);
      int idx= findInBuffer(buffer, curr, pos, contentEnd);
      if (idx != -1) {
        if (idx != pos) {
          resEdit.addChild(new DeleteEdit(pos, idx - pos));
        }
        pos= idx + curr.length();
      } else {
        resEdit.addChild(new InsertEdit(pos, curr));
      }
    }
    if (pos < contentEnd) {
      resEdit.addChild(new DeleteEdit(pos, contentEnd - pos));
    }
  }
View Full Code Here

    private static TextEdit createEditFromDiff(final Difference diff) {
        TextEdit result = null;

        // delete
        if (diff.getAddedEnd() == -1 && diff.getDeletedEnd() != -1) {
            result = new DeleteEdit(diff.getDeletedStart(), diff.getDeletedEnd()
                    - diff.getDeletedStart() + 1);
        }
        // replace
        else if (diff.getAddedEnd() != -1 && diff.getDeletedEnd() != -1) {
            result = createReplaceEdit(diff.getAddedStart(), diff.getAddedEnd(),
View Full Code Here

        result.addChild(new ReplaceEdit(deletedStart, minLength, getString(addedStart,
                addedStart + minLength - 1)));

        if (addedLength < deletedLength) {
            result.addChild(new DeleteEdit(deletedStart + minLength, deletedLength
                    - minLength));
        }

        return result;
    }
View Full Code Here

    // prefer to use use existing whitespace
    int existingWhitespaceOffset = whitespaceRun.indexOf(' ');
    if (existingWhitespaceOffset > -1) {
      // delete whitespaces before and after existing whitespace
      if (existingWhitespaceOffset > 0) {
        DeleteEdit deleteEdit = new DeleteEdit(spaceStartOffset, existingWhitespaceOffset);
        textEdit.addChild(deleteEdit);
      }
      if (existingWhitespaceOffset < whitespaceRun.length() - 1) {
        int nextOffset = existingWhitespaceOffset + 1;
        DeleteEdit deleteEdit = new DeleteEdit(spaceStartOffset + nextOffset, whitespaceRun.length() - nextOffset);
        textEdit.addChild(deleteEdit);
      }
    }
    else {
      // delete all whitespace and insert new one
      // collapse whitespace by deleting whitespace
      DeleteEdit deleteEdit = new DeleteEdit(spaceStartOffset, whitespaceRun.length());
      textEdit.addChild(deleteEdit);
      // then insert one space
      InsertEdit insertEdit = new InsertEdit(spaceStartOffset, SPACE);
      textEdit.addChild(insertEdit);
    }
View Full Code Here

  private void deleteTrailingSpaces(TextEdit textEdit, ITextRegion currentTextRegion, IStructuredDocumentRegion currentDocumentRegion) {
    int textEnd = currentTextRegion.getTextEnd();
    int textEndOffset = currentDocumentRegion.getStartOffset() + textEnd;
    int difference = currentTextRegion.getEnd() - textEnd;
    DeleteEdit deleteEdit = new DeleteEdit(textEndOffset, difference);
    textEdit.addChild(deleteEdit);
  }
View Full Code Here

          }
          else {
            // just collapse spaces, but adjust for any indenting that may result from preserving line delimiters
            if (whitespaceStart == 0 && XMLFormattingConstraints.IGNOREANDTRIM.equals(whitespaceMode)) {
              // if ignore, trim
              DeleteEdit deleteTrailing = new DeleteEdit(startOffset, whitespaceRun.length());
              textEdit.addChild(deleteTrailing);
            }
            else if(XMLFormattingConstraints.REPLACE.equals(whitespaceMode))
              availableLineWidth = replaceSpaces(textEdit, startOffset, availableLineWidth, whitespaceRun);
            else
              availableLineWidth = collapseAndIndent(textEdit, startOffset, availableLineWidth, indentLevel, whitespaceRun, currentRegion);
          }

          fullTextOffset += characterRunLength;
        }
        else {
          // handle trailing whitespace
          int whitespaceOffset = currentRegion.getStartOffset() + whitespaceStart;
          if (XMLFormattingConstraints.REPLACE.equals(whitespaceMode))
            availableLineWidth = replaceSpaces(textEdit, whitespaceOffset, availableLineWidth, whitespaceRun);
          else if (XMLFormattingConstraints.IGNOREANDTRIM.equals(whitespaceMode)) {
            // always trim
            DeleteEdit deleteTrailing = new DeleteEdit(whitespaceOffset, whitespaceRun.length());
            textEdit.addChild(deleteTrailing);
          }
          else if(getFormattingPreferences().getClearAllBlankLines()) {
            if (!nextRegionHandlesTrailingWhitespace(nextRegion)) {
              if (XMLFormattingConstraints.IGNORE.equals(whitespaceMode)) {
                // if ignore, trim
                DeleteEdit deleteTrailing = new DeleteEdit(whitespaceOffset, whitespaceRun.length());
                textEdit.addChild(deleteTrailing);
              }
              else {
                // if collapse, leave a space. but what if end up
                // wanting to add indent? then need to delete space
View Full Code Here

    for (int i= 0; i < stringsToInsert.size(); i++) {
      String curr= (String) stringsToInsert.get(i);
      int idx= findInBuffer(buffer, curr, pos, contentEnd);
      if (idx != -1) {
        if (idx != pos) {
          resEdit.addChild(new DeleteEdit(pos, idx - pos));
        }
        pos= idx + curr.length();
      } else {
        resEdit.addChild(new InsertEdit(pos, curr));
      }
    }
    if (pos < contentEnd) {
      resEdit.addChild(new DeleteEdit(pos, contentEnd - pos));
    }
  }
View Full Code Here

  final TextEdit doTextRemove(int offset, int len, TextEditGroup editGroup) {
    if (len == 0) {
      return null;
    }
    TextEdit edit= new DeleteEdit(offset, len);
    addEdit(edit);
    if (editGroup != null) {
      addEditGroup(editGroup, edit);
    }
    return edit;
View Full Code Here

          continue;
        }
        if (rootEdit == null) {
          rootEdit = new MultiTextEdit();
        }
        rootEdit.addChild(new DeleteEdit(charPos, lineEnd - charPos));
      }
    }
    return rootEdit;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.text.edits.DeleteEdit

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.