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 / +40 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 last = getLineAtOffset(event.fOffset + event.fLength - 1);
282
        changeEvent.replaceLineCount= last - first;
285
        changeEvent.replaceLineCount = Math.max(last - first, 0);
283
        
286
     
284
        changeEvent.newLineCount = countLines(event.fText);
287
        int newLineCount = countNewLines(event.fText);
285
        
288
		changeEvent.newLineCount = newLineCount >= 0 ? newLineCount : 0;
289
286
        if (changeEvent.newLineCount > offsets.length-regionCount) {
290
        if (changeEvent.newLineCount > offsets.length-regionCount) {
287
            growRegionArray(changeEvent.newLineCount);
291
            growRegionArray(changeEvent.newLineCount);
288
        }
292
        }
Lines 303-349 Link Here
303
        lengths = newLengths;
307
        lengths = newLengths;
304
    }
308
    }
305
309
306
    /**
310
    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;
311
		int count = 0;
313
		
312
		
314
		int lastDelimiter = 0;
313
		if (string.length() == 0) return 0;
315
		for (int i = 0; i < line.length(); i++) {
314
316
			char c = line.charAt(i);
315
		// work around to
317
			if (c == '\n') {
316
		// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4994840
318
				count++;
317
		// see bug 84641
319
				if (consoleWidth > 0) {
318
		if (string.endsWith("\r")) { //$NON-NLS-1$
320
					count += (i-lastDelimiter)/consoleWidth;
319
			int len = string.length();
321
				}
320
			int index = len >= 2 ? len - 2 : 0;
322
				lastDelimiter = i;
321
			string = string.substring(0, index);
323
			} else if (c == '\r') {
322
			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
		}
323
		}
337
		
324
		
338
		if (lastDelimiter < line.length()) {
325
		int lastIndex = 0;
339
			count++;
326
		int index = 0;
327
		
328
		Matcher matcher = pattern.matcher(string);
329
		
330
		while (matcher.find()) {
331
			index = matcher.start();
332
			
333
			if (index == 0)
334
				count++;
335
			else if (index!=string.length())
336
				count++;
337
			
340
			if (consoleWidth > 0) {
338
			if (consoleWidth > 0) {
341
				count += (line.length()-lastDelimiter)/consoleWidth;
339
				int lineLen = index - lastIndex + 1;
340
				if (index == 0) lineLen += lengths[regionCount-1];
341
				count += lineLen/consoleWidth;
342
			}
342
			}
343
			
344
			lastIndex = index;
343
		}
345
		}
344
		
345
		return count;
346
		return count;
346
    }
347
	}
347
348
348
349
349
    /* (non-Javadoc)
350
    /* (non-Javadoc)

Return to bug 137694