Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 99299
Collapse All | Expand All

(-)Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DefaultContent.java (+47 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Patrick Tasse - [99299] DefaultContent.getLine(DefaultContent.java:489) - java.lang.StringIndexOutOfBoundsException 
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.swt.custom;
12
package org.eclipse.swt.custom;
12
13
Lines 267-272 Link Here
267
	boolean endInsert = position == getCharCount();
268
	boolean endInsert = position == getCharCount();
268
	adjustGap(position, change, startLine);
269
	adjustGap(position, change, startLine);
269
270
271
	// if the beginning of the inserted text is continuing a CR+LF delimiter
272
	// then append LF to the previous line and adjust the start line and gap
273
	// and then continue with the remaining text to insert, if any
274
	if (text.charAt(0) == SWT.LF && startLine > 0 && lines[startLine][0] == position) {
275
		if (textStore[position - 1] == SWT.CR) {
276
			textStore[position++] = SWT.LF;
277
			lines[startLine - 1][1]++;
278
			lines[startLine][0]++;
279
			lines[startLine][1]--;
280
			gapStart++;
281
			text = text.substring(1);
282
			if (text.length() == 0) return;
283
		}
284
	}
285
	
286
	// if the end of the inserted text is creating a CR+LF delimiter from a LF
287
	// then insert the CR at the end of the gap on the current line and adjust the gap
288
	// and then continue with the remaining text to insert, if any
289
	if (text.charAt(text.length() - 1) == SWT.CR && gapEnd < textStore.length && textStore[gapEnd] == SWT.LF) {
290
		textStore[--gapEnd] = SWT.CR;
291
		text = text.substring(0, text.length() - 1);
292
		if (text.length() == 0) return;
293
	}
294
	
270
	// during an insert the gap will be adjusted to start at
295
	// during an insert the gap will be adjusted to start at
271
	// position and it will be associated with startline, the
296
	// position and it will be associated with startline, the
272
	// inserted text will be placed in the gap		
297
	// inserted text will be placed in the gap		
Lines 837-842 Link Here
837
	}
862
	}
838
863
839
	adjustGap(position + length, -length, startLine);
864
	adjustGap(position + length, -length, startLine);
865
	
866
	// if the characters before and after the deleted text are creating a CR+LF
867
	// then shift the text to delete by one, append a LF to the previous line,
868
	// add a LF to the text to delete, adjust the previous line, start line and gap,
869
	// and then continue with the augmented text to delete
870
	if (position > 0 && textStore[position - 1] == SWT.CR && gapEnd < textStore.length && textStore[gapEnd] == SWT.LF) {
871
		for (int i = position + length; i > position; i--) {
872
			textStore[i] = textStore[i - 1];
873
		}
874
		gapStart++;
875
		textStore[gapEnd++] = 0;
876
		textStore[position++] = SWT.LF;
877
		textStore[gapStart++] = SWT.LF;
878
		lines[startLine - 1][1]++;
879
		lines[startLine][0]++;
880
		lines[startLine][1]--;
881
		length++;
882
		numLines++;
883
		startLineOffset++;
884
		endLine++;
885
	}
886
	
840
	int [][] oldLines = indexLines(position, length + (gapEnd - gapStart), numLines);
887
	int [][] oldLines = indexLines(position, length + (gapEnd - gapStart), numLines);
841
	
888
	
842
	// enlarge the gap - the gap can be enlarged either to the
889
	// enlarge the gap - the gap can be enlarged either to the

Return to bug 99299