use of com.intellij.util.text.ImmutableCharSequence in project intellij-community by JetBrains.
the class DocumentImpl method replaceString.
private void replaceString(int startOffset, int endOffset, @NotNull CharSequence s, final long newModificationStamp, boolean wholeTextReplaced) {
assertBounds(startOffset, endOffset);
assertWriteAccess();
assertValidSeparators(s);
if (!isWritable()) {
throw new ReadOnlyModificationException(this);
}
int initialStartOffset = startOffset;
int initialOldLength = endOffset - startOffset;
final int newStringLength = s.length();
final CharSequence chars = myText;
int newStartInString = 0;
while (newStartInString < newStringLength && startOffset < endOffset && s.charAt(newStartInString) == chars.charAt(startOffset)) {
startOffset++;
newStartInString++;
}
int newEndInString = newStringLength;
while (endOffset > startOffset && newEndInString > newStartInString && s.charAt(newEndInString - 1) == chars.charAt(endOffset - 1)) {
newEndInString--;
endOffset--;
}
if (startOffset == 0 && endOffset == getTextLength()) {
wholeTextReplaced = true;
}
CharSequence changedPart = s.subSequence(newStartInString, newEndInString);
CharSequence sToDelete = myText.subtext(startOffset, endOffset);
RangeMarker guard = getRangeGuard(startOffset, endOffset);
if (guard != null) {
throwGuardedFragment(guard, startOffset, sToDelete, changedPart);
}
ImmutableCharSequence newText;
if (wholeTextReplaced && s instanceof ImmutableCharSequence) {
newText = (ImmutableCharSequence) s;
} else {
newText = myText.delete(startOffset, endOffset).insert(startOffset, changedPart);
changedPart = newText.subtext(startOffset, startOffset + changedPart.length());
}
updateText(newText, startOffset, sToDelete, changedPart, wholeTextReplaced, newModificationStamp, initialStartOffset, initialOldLength);
trimToSize();
}
use of com.intellij.util.text.ImmutableCharSequence in project intellij-community by JetBrains.
the class FrozenDocument method applyEvent.
public FrozenDocument applyEvent(DocumentEvent event, int newStamp) {
final int offset = event.getOffset();
final int oldEnd = offset + event.getOldLength();
ImmutableCharSequence newText = myText.delete(offset, oldEnd).insert(offset, event.getNewFragment());
LineSet newLineSet = getLineSet().update(myText, offset, oldEnd, event.getNewFragment(), event.isWholeTextReplaced());
return new FrozenDocument(newText, newLineSet, newStamp, null);
}
use of com.intellij.util.text.ImmutableCharSequence in project intellij-community by JetBrains.
the class DocumentImpl method updateText.
private void updateText(@NotNull ImmutableCharSequence newText, int offset, @NotNull CharSequence oldString, @NotNull CharSequence newString, boolean wholeTextReplaced, long newModificationStamp, int initialStartOffset, int initialOldLength) {
assertNotNestedModification();
myChangeInProgress = true;
try {
DocumentEvent event = new DocumentEventImpl(this, offset, oldString, newString, myModificationStamp, wholeTextReplaced, initialStartOffset, initialOldLength);
beforeChangedUpdate(event);
myTextString = null;
ImmutableCharSequence prevText = myText;
myText = newText;
// increment sequence before firing events so that modification sequence on commit will match this sequence now
sequence.incrementAndGet();
changedUpdate(event, newModificationStamp, prevText);
} finally {
myChangeInProgress = false;
}
}
use of com.intellij.util.text.ImmutableCharSequence in project intellij-community by JetBrains.
the class DocumentImpl method insertString.
@Override
public void insertString(int offset, @NotNull CharSequence s) {
if (offset < 0)
throw new IndexOutOfBoundsException("Wrong offset: " + offset);
if (offset > getTextLength()) {
throw new IndexOutOfBoundsException("Wrong offset: " + offset + "; documentLength: " + getTextLength() + "; " + s.subSequence(Math.max(0, s.length() - 20), s.length()));
}
assertWriteAccess();
assertValidSeparators(s);
if (!isWritable())
throw new ReadOnlyModificationException(this);
if (s.length() == 0)
return;
RangeMarker marker = getRangeGuard(offset, offset);
if (marker != null) {
throwGuardedFragment(marker, offset, "", s);
}
ImmutableCharSequence newText = myText.insert(offset, s);
ImmutableCharSequence newString = newText.subtext(offset, offset + s.length());
updateText(newText, offset, "", newString, false, LocalTimeCounter.currentTime(), offset, 0);
trimToSize();
}
use of com.intellij.util.text.ImmutableCharSequence in project intellij-community by JetBrains.
the class DocumentImpl method deleteString.
@Override
public void deleteString(int startOffset, int endOffset) {
assertBounds(startOffset, endOffset);
assertWriteAccess();
if (!isWritable())
throw new ReadOnlyModificationException(this);
if (startOffset == endOffset)
return;
RangeMarker marker = getRangeGuard(startOffset, endOffset);
if (marker != null) {
throwGuardedFragment(marker, startOffset, myText.subSequence(startOffset, endOffset), "");
}
ImmutableCharSequence newText = myText.delete(startOffset, endOffset);
ImmutableCharSequence oldString = myText.subtext(startOffset, endOffset);
updateText(newText, startOffset, oldString, "", false, LocalTimeCounter.currentTime(), startOffset, endOffset - startOffset);
}
Aggregations