if (afterRemove < fGapStart) { final int betweenSize= fGapStart - afterRemove; arrayCopy(afterRemove, fContent, newGapEnd, betweenSize); final int offsetShifted= offset + oldGapSize; final int betweenSize= offsetShifted - fGapEnd; // in the typing case, betweenSize is 0 arrayCopy(fGapEnd, fContent, fGapStart, betweenSize);
/** * Moves the gap to <code>offset + add</code>, moving any content after * <code>offset + remove</code> behind the gap. The gap size is kept between 0 and * {@link #fThreshold}, leading to re-allocation if needed. The content between * <code>offset</code> and <code>offset + add</code> is undefined after this operation. * * @param offset the offset at which a change happens * @param remove the number of character which are removed or overwritten at <code>offset</code> * @param add the number of character which are inserted or overwriting at <code>offset</code> */ private void adjustGap(int offset, int remove, int add) { final int oldGapSize= gapSize(); final int newGapSize= oldGapSize - add + remove; final boolean reuseArray= 0 <= newGapSize && newGapSize <= fThreshold; final int newGapStart= offset + add; final int newGapEnd; if (reuseArray) newGapEnd= moveGap(offset, remove, oldGapSize, newGapSize, newGapStart); else newGapEnd= reallocate(offset, remove, oldGapSize, newGapSize, newGapStart); fGapStart= newGapStart; fGapEnd= newGapEnd; }
@Override public final void set(String text) { /* * Moves the gap to the end of the content. There is no sensible prediction of where the * next change will occur, but at least the next change will not trigger re-allocation. This * is especially important when using the GapTextStore within a CopyOnWriteTextStore, where * the GTS is only initialized right before a modification. */ replace(0, getLength(), text); }
/** * Creates a new empty document. */ public Document() { super(); setTextStore(new CopyOnWriteTextStore(new GapTextStore())); setLineTracker(new DefaultLineTracker()); completeInitialization(); }
final char[] newContent= allocate(newArraySize); final int newGapEnd= newGapStart + newGapSize; arrayCopy(0, newContent, 0, offset); int afterRemove= offset + remove; if (afterRemove < fGapStart) { arrayCopy(afterRemove, newContent, newGapEnd, betweenSize); final int restSize= fContent.length - fGapEnd; arrayCopy(fGapEnd, newContent, newGapEnd + betweenSize, restSize); } else { arrayCopy(afterRemove, newContent, newGapEnd, restSize); arrayCopy(0, newContent, 0, fGapStart); final int offsetShifted= offset + oldGapSize; final int betweenSize= offsetShifted - fGapEnd; arrayCopy(fGapEnd, newContent, fGapStart, betweenSize); final int afterRemove= offsetShifted + remove; final int restSize= fContent.length - afterRemove; arrayCopy(afterRemove, newContent, newGapEnd, restSize);
@Override public final char get(int offset) { if (offset < fGapStart) return fContent[offset]; return fContent[offset + gapSize()]; }
/** * Creates a new empty document. */ public Document() { super(); setTextStore(new CopyOnWriteTextStore(new GapTextStore())); setLineTracker(new DefaultLineTracker()); completeInitialization(); }
@Override public final void set(String text) { /* * Moves the gap to the end of the content. There is no sensible prediction of where the * next change will occur, but at least the next change will not trigger re-allocation. This * is especially important when using the GapTextStore within a CopyOnWriteTextStore, where * the GTS is only initialized right before a modification. */ replace(0, getLength(), text); }
final char[] newContent= allocate(newArraySize); final int newGapEnd= newGapStart + newGapSize; arrayCopy(0, newContent, 0, offset); int afterRemove= offset + remove; if (afterRemove < fGapStart) { arrayCopy(afterRemove, newContent, newGapEnd, betweenSize); final int restSize= fContent.length - fGapEnd; arrayCopy(fGapEnd, newContent, newGapEnd + betweenSize, restSize); } else { arrayCopy(afterRemove, newContent, newGapEnd, restSize); arrayCopy(0, newContent, 0, fGapStart); final int offsetShifted= offset + oldGapSize; final int betweenSize= offsetShifted - fGapEnd; arrayCopy(fGapEnd, newContent, fGapStart, betweenSize); final int afterRemove= offsetShifted + remove; final int restSize= fContent.length - afterRemove; arrayCopy(afterRemove, newContent, newGapEnd, restSize);
@Override public final char get(int offset) { if (offset < fGapStart) return fContent[offset]; return fContent[offset + gapSize()]; }
/** * Creates a new document with the given initial content. * * @param initialContent the document's initial content */ public Document(String initialContent) { super(); setTextStore(new CopyOnWriteTextStore(new GapTextStore())); setLineTracker(new DefaultLineTracker()); getStore().set(initialContent); getTracker().set(initialContent); completeInitialization(); }
/** * Moves the gap to <code>offset + add</code>, moving any content after * <code>offset + remove</code> behind the gap. The gap size is kept between 0 and * {@link #fThreshold}, leading to re-allocation if needed. The content between * <code>offset</code> and <code>offset + add</code> is undefined after this operation. * * @param offset the offset at which a change happens * @param remove the number of character which are removed or overwritten at <code>offset</code> * @param add the number of character which are inserted or overwriting at <code>offset</code> */ private void adjustGap(int offset, int remove, int add) { final int oldGapSize= gapSize(); final int newGapSize= oldGapSize - add + remove; final boolean reuseArray= 0 <= newGapSize && newGapSize <= fThreshold; final int newGapStart= offset + add; final int newGapEnd; if (reuseArray) newGapEnd= moveGap(offset, remove, oldGapSize, newGapSize, newGapStart); else newGapEnd= reallocate(offset, remove, oldGapSize, newGapSize, newGapStart); fGapStart= newGapStart; fGapEnd= newGapEnd; }
@Override public final int getLength() { return fContent.length - gapSize(); }
if (afterRemove < fGapStart) { final int betweenSize= fGapStart - afterRemove; arrayCopy(afterRemove, fContent, newGapEnd, betweenSize); final int offsetShifted= offset + oldGapSize; final int betweenSize= offsetShifted - fGapEnd; // in the typing case, betweenSize is 0 arrayCopy(fGapEnd, fContent, fGapStart, betweenSize);
/** * Creates a new document with the given initial content. * * @param initialContent the document's initial content */ public Document(String initialContent) { super(); setTextStore(new CopyOnWriteTextStore(new GapTextStore())); setLineTracker(new DefaultLineTracker()); getStore().set(initialContent); getTracker().set(initialContent); completeInitialization(); }
@Override public final int getLength() { return fContent.length - gapSize(); }
masterDocument.addDocumentListener(this); setTextStore(new CopyOnWriteTextStore(new GapTextStore())); setLineTracker(new DefaultLineTracker()); getStore().set(masterDocument.get());
@Override public final String get(int offset, int length) { if (fGapStart <= offset) return new String(fContent, offset + gapSize() , length); final int end= offset + length; if (end <= fGapStart) return new String(fContent, offset, length); StringBuilder buf= new StringBuilder(length); // see Bug 113871 buf.append(fContent, offset, fGapStart - offset); buf.append(fContent, fGapEnd, end - fGapStart); return buf.toString(); }