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 137694 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/console/ConsoleDocumentAdapter.java (-39 / +41 lines)
Lines 13-18 Link Here
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Iterator;
14
import java.util.Iterator;
15
import java.util.List;
15
import java.util.List;
16
import java.util.regex.Matcher;
17
import java.util.regex.Pattern;
16
18
17
import org.eclipse.jface.text.Assert;
19
import org.eclipse.jface.text.Assert;
18
import org.eclipse.jface.text.BadLocationException;
20
import org.eclipse.jface.text.BadLocationException;
Lines 41-47 Link Here
41
    
43
    
42
    int[] offsets = new int[5000];
44
    int[] offsets = new int[5000];
43
    int[] lengths = new int[5000];
45
    int[] lengths = new int[5000];
44
    private int regionCount = 0;
46
    private int regionCount = 1;
47
    private Pattern pattern = Pattern.compile("$", Pattern.MULTILINE); //$NON-NLS-1$
45
    
48
    
46
    
49
    
47
    public ConsoleDocumentAdapter(int width) {
50
    public ConsoleDocumentAdapter(int width) {
Lines 278-288 Link Here
278
        changeEvent.newCharCount = (event.fText == null ? 0 : event.fText.length());
281
        changeEvent.newCharCount = (event.fText == null ? 0 : event.fText.length());
279
        
282
        
280
        int first = getLineAtOffset(event.fOffset);
283
        int first = getLineAtOffset(event.fOffset);
281
        int last = getLineAtOffset(event.fOffset + event.fLength);
284
        int lOffset = Math.max(event.fOffset + event.fLength - 1, 0);
282
        changeEvent.replaceLineCount= last - first;
285
		int last = getLineAtOffset(lOffset);
283
        
286
        changeEvent.replaceLineCount = Math.max(last - first, 0);
284
        changeEvent.newLineCount = countLines(event.fText);
287
     
285
        
288
        int newLineCount = countNewLines(event.fText);
289
		changeEvent.newLineCount = newLineCount >= 0 ? newLineCount : 0;
290
286
        if (changeEvent.newLineCount > offsets.length-regionCount) {
291
        if (changeEvent.newLineCount > offsets.length-regionCount) {
287
            growRegionArray(changeEvent.newLineCount);
292
            growRegionArray(changeEvent.newLineCount);
288
        }
293
        }
Lines 303-349 Link Here
303
        lengths = newLengths;
308
        lengths = newLengths;
304
    }
309
    }
305
310
306
    /**
311
    private int countNewLines(String string) {
307
     * Counts the number of lines the viewer's text widget will need to use to 
308
     * display the String
309
     * @return The number of lines necessary to display the string in the viewer.
310
     */
311
    private int countLines(String line) {
312
		int count = 0;
312
		int count = 0;
313
		
313
		
314
		int lastDelimiter = 0;
314
		if (string.length() == 0) return 0;
315
		for (int i = 0; i < line.length(); i++) {
315
316
			char c = line.charAt(i);
316
		// work around to
317
			if (c == '\n') {
317
		// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4994840
318
				count++;
318
		// see bug 84641
319
				if (consoleWidth > 0) {
319
		if (string.endsWith("\r")) { //$NON-NLS-1$
320
					count += (i-lastDelimiter)/consoleWidth;
320
			int len = string.length();
321
				}
321
			int index = len >= 2 ? len - 2 : 0;
322
				lastDelimiter = i;
322
			string = string.substring(0, index);
323
			} else if (c == '\r') {
323
			count++;
324
				count++;
325
				if (consoleWidth > 0) {
326
					count += (i-lastDelimiter)/consoleWidth;
327
				}
328
				if (i+1 < line.length()) {
329
					char next = line.charAt(i+1);
330
					if (next == '\n') {
331
						i++;
332
					}
333
				}
334
				lastDelimiter = i;
335
			}
336
		}
324
		}
337
		
325
		
338
		if (lastDelimiter < line.length()) {
326
		int lastIndex = 0;
339
			count++;
327
		int index = 0;
328
		
329
		Matcher matcher = pattern.matcher(string);
330
		
331
		while (matcher.find()) {
332
			index = matcher.start();
333
			
334
			if (index == 0)
335
				count++;
336
			else if (index!=string.length())
337
				count++;
338
			
340
			if (consoleWidth > 0) {
339
			if (consoleWidth > 0) {
341
				count += (line.length()-lastDelimiter)/consoleWidth;
340
				int lineLen = index - lastIndex + 1;
341
				if (index == 0) lineLen += lengths[regionCount-1];
342
				count += lineLen/consoleWidth;
342
			}
343
			}
344
			
345
			lastIndex = index;
343
		}
346
		}
344
		
345
		return count;
347
		return count;
346
    }
348
	}
347
349
348
350
349
    /* (non-Javadoc)
351
    /* (non-Javadoc)

Return to bug 137694