Index: javax/swing/text/GapContent.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/GapContent.java,v retrieving revision 1.26 diff -u -r1.26 GapContent.java --- javax/swing/text/GapContent.java 13 Sep 2005 23:22:27 -0000 1.26 +++ javax/swing/text/GapContent.java 29 Sep 2005 17:20:30 -0000 @@ -116,7 +116,7 @@ public int getOffset() { // Check precondition. - assert mark <= gapStart || mark > gapEnd : "mark: " + mark + assert mark <= gapStart || mark >= gapEnd : "mark: " + mark + ", gapStart: " + gapStart + ", gapEnd: " + gapEnd; @@ -379,7 +379,7 @@ if (index < 0) index = -(index + 1); positions.add(index, pos); - + return pos; } @@ -426,13 +426,12 @@ return; int newGapEnd = newGapStart + gapEnd - gapStart; - if (newGapStart < gapStart) { // Update the positions between newGapStart and (old) gapStart. The marks // must be shifted by (gapEnd - gapStart). - Vector v = getPositionsInRange(null, newGapStart + 1, - gapStart - newGapStart + 1); + Vector v = getPositionsInRange(null, newGapStart, + gapStart - newGapStart); for (Iterator i = v.iterator(); i.hasNext();) { GapContentPosition p = (GapContentPosition) i.next(); @@ -459,6 +458,8 @@ gapStart = newGapStart; gapEnd = newGapEnd; } + if (gapStart == 0) + resetMarksAtZero(); } /** @@ -530,9 +531,11 @@ protected void replace(int position, int rmSize, Object addItems, int addSize) { + if (gapStart != position) + shiftGap(position); // Remove content - shiftGap(position); - shiftGapEndUp(gapEnd + rmSize); + if (rmSize > 0) + shiftGapEndUp(gapEnd + rmSize); // If gap is too small, enlarge the gap. if ((gapEnd - gapStart) <= addSize) @@ -604,5 +607,24 @@ res.add(p); } return res; + } + + /** + * Resets all Position that have an offset of 0, + * to also have an array index of 0. This might be necessary + * after a call to shiftGap(0), since then the marks at offset + * 0 get shifted to gapEnd. + */ + protected void resetMarksAtZero() + { + if (gapStart != 0) + return; + + Vector zeroMarks = getPositionsInRange(null, gapEnd, 0); + for (Iterator i = zeroMarks.iterator(); i.hasNext();) + { + GapContentPosition pos = (GapContentPosition) i.next(); + pos.mark = 0; + } } }