Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-07-02 09:32:12 +0000
committerPaul Pazderski2019-07-02 09:35:50 +0000
commit999fda5f46e5566560ede1638b730d561f650ab2 (patch)
tree4b55c4c63d315f1af230beee86a8b2707fd269b5
parent1962d9672d5af1a8c4d749a819be3d9784bf9ee0 (diff)
downloadeclipse.platform.debug-999fda5f46e5566560ede1638b730d561f650ab2.tar.gz
eclipse.platform.debug-999fda5f46e5566560ede1638b730d561f650ab2.tar.xz
eclipse.platform.debug-999fda5f46e5566560ede1638b730d561f650ab2.zip
Bug 548356 - [console] Fix wrong input handling with multiline paste
The last input handling fix changed (unintentional) the behavior on pasting multiline input. Change-Id: Ib302ec08043b2f5aedafaec9e2d796ef82645f2f Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java75
1 files changed, 44 insertions, 31 deletions
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java
index edb7af0b0..1c86d080f 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/IOConsolePartitioner.java
@@ -418,18 +418,52 @@ public class IOConsolePartitioner implements IConsoleDocumentPartitioner, IDocum
lastPartitionWithValidOffset--;
inputPartition = getPartitionByIndex(inputPartitionIndex);
}
- if (inputPartition == null || inputPartition.isReadOnly()) {
- if (inputPartition != null && offset < inputPartition.getOffset() + inputPartition.getLength()) {
- // input is inside an existing read-only partition
- splitPartition(offset);
+
+ // process event text in parts split on line delimiters
+ int textOffset = 0;
+ while (textOffset < eventTextLength) {
+ final int[] result = TextUtilities.indexOf(lld, event.getText(), textOffset);
+ final boolean foundNewline = result[1] >= 0;
+ final int newTextOffset = foundNewline ? result[0] + lld[result[1]].length() : eventTextLength;
+ final int inputLength = newTextOffset - textOffset;
+
+ if (inputPartition == null || inputPartition.isReadOnly()) {
+ final int inputOffset = offset + textOffset;
+ if (inputPartition != null
+ && inputOffset < inputPartition.getOffset() + inputPartition.getLength()) {
+ // input is inside an existing read-only partition
+ splitPartition(inputOffset);
+ }
+ inputPartition = new IOConsolePartition(inputOffset, inputStream);
+ inputPartitionIndex++;
+ partitions.add(inputPartitionIndex, inputPartition);
+ inputPartitions.add(inputPartition);
+ lastPartitionWithValidOffset++; // new input partitions get build with correct offsets
+ }
+
+ inputPartition.setLength(inputPartition.getLength() + inputLength);
+
+ if (foundNewline) {
+ inputPartitions.sort(CMP_REGION_BY_OFFSET);
+ final StringBuilder inputLine = new StringBuilder();
+ for (IOConsolePartition p : inputPartitions) {
+ try {
+ final String fragment = document.get(p.getOffset(), p.getLength());
+ inputLine.append(fragment);
+ } catch (BadLocationException e) {
+ log(e);
+ }
+ p.setReadOnly();
+ }
+ inputPartitions.clear();
+ if (ASSERT) {
+ Assert.isTrue(inputLine.length() > 0);
+ }
+ inputStream.appendData(inputLine.toString());
}
- inputPartition = new IOConsolePartition(offset, inputStream);
- inputPartitionIndex++;
- partitions.add(inputPartitionIndex, inputPartition);
- inputPartitions.add(inputPartition);
- lastPartitionWithValidOffset++; // new input partitions get build with correct offsets
+ Assert.isTrue(newTextOffset > textOffset); // can prevent infinity loop
+ textOffset = newTextOffset;
}
- inputPartition.setLength(inputPartition.getLength() + eventTextLength);
}
// repair partition offsets
@@ -459,27 +493,6 @@ public class IOConsolePartitioner implements IConsoleDocumentPartitioner, IDocum
}
}
- // send pending input if event contains line delimiter
- final int[] result = TextUtilities.indexOf(lld, event.getText(), 0);
- if (result[1] >= 0) {
- inputPartitions.sort(CMP_REGION_BY_OFFSET);
- final StringBuilder inputLine = new StringBuilder();
- for (IOConsolePartition p : inputPartitions) {
- try {
- final String fragment = document.get(p.getOffset(), p.getLength());
- inputLine.append(fragment);
- } catch (BadLocationException e) {
- log(e);
- }
- p.setReadOnly();
- }
- inputPartitions.clear();
- if (ASSERT) {
- Assert.isTrue(inputLine.length() > 0);
- }
- inputStream.appendData(inputLine.toString());
- }
-
if (ASSERT) {
checkPartitions();
}

Back to the top