diff --git a/debug/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java b/debug/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java index 4d1f5b97591..dd12bf2c546 100644 --- a/debug/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java +++ b/debug/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java @@ -784,7 +784,7 @@ public boolean shouldRun() { * update partitioning. */ private void processPendingPartitions() { - final List pendingCopy = new ArrayList<>(); + List pendingCopy = new ArrayList<>(); // draining the whole buffer here is important - this way we get as much data as // available and may skip to draw text that exceeds the Console buffer size // anyway (see checkBufferSize()). @@ -793,12 +793,40 @@ private void processPendingPartitions() { if (pendingCopy.isEmpty()) { return; } + int pendingSize = 0; IOConsoleOutputStream stream = pendingCopy.get(0).stream; for (PendingPartition p : pendingCopy) { - if (p.stream != stream) { - break; + if (p.stream == stream) { + sizeHint += p.text.length(); + } + pendingSize += p.text.length(); + } + /* + * Check if the output we want to process is over the console limit. If so, trim + * the output before passing it to SWT. + */ + int limit = highWaterMark; + if (limit > 0 && pendingSize > limit) { + sizeHint = Math.min(sizeHint, limit); + int n = pendingCopy.size(); + // check at which pending change we need to cut the output, to comply with the character limit + int index = 0; + int characters = 0; + for (int i = n - 1; i >= 0; --i) { + PendingPartition p = pendingCopy.get(i); + characters += p.text.length(); + index = i; + if (characters > limit) { + break; + } + } + // copy from that index onward + List trimmedCopy = new ArrayList<>(n - index); + for (int i = index; i < n; ++i) { + PendingPartition p = pendingCopy.get(i); + trimmedCopy.add(p); } - sizeHint += p.text.length(); + pendingCopy = trimmedCopy; } synchronized (partitions) { if (document != null) {