Exemplo n.º 1
0
  public void endCompoundEdit() {
    if (compoundEditCount == 0) {
      Log.log(Log.WARNING, this, new Exception("Unbalanced begin/endCompoundEdit()"));
      return;
    } else if (compoundEditCount == 1) {
      if (compoundEdit.first == null) ;
      else if (compoundEdit.first == compoundEdit.last) addEdit(compoundEdit.first);
      else addEdit(compoundEdit);

      compoundEdit = null;
    }

    compoundEditCount--;
  }
Exemplo n.º 2
0
  public void contentInserted(int offset, int length, String text, boolean clearDirty) {
    Edit last = getLastEdit();
    Edit toMerge = getMergeEdit();

    if (!clearDirty && toMerge instanceof Insert && redosFirst == null) {
      Insert ins = (Insert) toMerge;
      if (ins.offset == offset) {
        ins.str = text.concat(ins.str);
        ins.length += length;
        return;
      } else if (ins.offset + ins.length == offset) {
        ins.str = ins.str.concat(text);
        ins.length += length;
        return;
      }
    }

    Insert ins = new Insert(this, offset, length, text);

    if (clearDirty) {
      redoClearDirty = last;
      undoClearDirty = ins;
    }

    if (compoundEdit != null) compoundEdit.add(ins);
    else {
      reviseUndoId();
      addEdit(ins);
    }
  }
Exemplo n.º 3
0
  public void contentRemoved(int offset, int length, String text, boolean clearDirty) {
    Edit last = getLastEdit();
    Edit toMerge = getMergeEdit();

    if (!clearDirty && toMerge instanceof Remove && redosFirst == null) {
      Remove rem = (Remove) toMerge;
      if (rem.offset == offset) {
        rem.content.str = rem.content.str.concat(text);
        rem.content.hashcode = rem.content.str.hashCode();
        rem.length += length;
        KillRing.getInstance().changed(rem.content);
        return;
      } else if (offset + length == rem.offset) {
        rem.content.str = text.concat(rem.content.str);
        rem.content.hashcode = rem.content.str.hashCode();
        rem.length += length;
        rem.offset = offset;
        KillRing.getInstance().changed(rem.content);
        return;
      }
    }

    Remove rem = new Remove(this, offset, length, text);
    if (clearDirty) {
      redoClearDirty = last;
      undoClearDirty = rem;
    }

    if (compoundEdit != null) compoundEdit.add(rem);
    else {
      reviseUndoId();
      addEdit(rem);
    }

    KillRing.getInstance().add(rem.content);
  }
Exemplo n.º 4
0
  // {{{ contentRemoved() method
  public void contentRemoved(int offset, int length, String text, boolean clearDirty) {
    Edit toMerge = getMergeEdit();

    if (!clearDirty && toMerge instanceof Remove && redosFirst == null) {
      Remove rem = (Remove) toMerge;
      if (rem.offset == offset) {
        String newStr = rem.str.concat(text);
        KillRing.getInstance().changed(rem.str, newStr);
        rem.str = newStr;
        return;
      } else if (offset + length == rem.offset) {
        String newStr = text.concat(rem.str);
        KillRing.getInstance().changed(rem.str, newStr);
        rem.offset = offset;
        rem.str = newStr;
        return;
      }
    }

    // use String.intern() here as new Strings are created in
    // JEditBuffer.remove() via undoMgr.contentRemoved(... getText() ...);
    Remove rem = new Remove(offset, text.intern());

    if (clearDirty) {
      redoClearDirty = getLastEdit();
      undoClearDirty = rem;
    }

    if (compoundEdit != null) compoundEdit.add(this, rem);
    else {
      reviseUndoId();
      addEdit(rem);
    }

    KillRing.getInstance().add(rem.str);
  } // }}}