Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2010-03-22 17:01:56 +0000
committerDani Megert2010-03-22 17:01:56 +0000
commitadabfc14b76c4383cd79e612df848a99b8ed1ce4 (patch)
tree28b481f91e5097693a111985c5660ab75ed2619e
parentf3f5fe0af9cb4a5201c5f41500b52ff4e5c69105 (diff)
downloadeclipse.platform.text-20100323-0800.tar.gz
eclipse.platform.text-20100323-0800.tar.xz
eclipse.platform.text-20100323-0800.zip
Committed Anton's patch to fix bug 301023: [projection][typing] "Backspace" key deleting something elsev20100323-0800
-rw-r--r--org.eclipse.text.tests/projection/org/eclipse/text/tests/ProjectionDocumentTest.java55
-rw-r--r--org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java7
2 files changed, 54 insertions, 8 deletions
diff --git a/org.eclipse.text.tests/projection/org/eclipse/text/tests/ProjectionDocumentTest.java b/org.eclipse.text.tests/projection/org/eclipse/text/tests/ProjectionDocumentTest.java
index 6fd892480..baf5a85f4 100644
--- a/org.eclipse.text.tests/projection/org/eclipse/text/tests/ProjectionDocumentTest.java
+++ b/org.eclipse.text.tests/projection/org/eclipse/text/tests/ProjectionDocumentTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Anton Leherbauer <anton.leherbauer@windriver.com> - [projection] "Backspace" key deleting something else - http://bugs.eclipse.org/301023
*******************************************************************************/
package org.eclipse.text.tests;
@@ -203,7 +204,7 @@ public class ProjectionDocumentTest extends TestCase {
Position previous= null;
for (int i= 0; i < segmentation.length; i++) {
- assertFalse(segmentation.length > 1 && segmentation[i].getLength() == 0);
+ assertFalse(segmentation.length > 1 && (segmentation[i].getLength() == 0 && i < segmentation.length - 1));
if (previous != null)
assertTrue(previous.getOffset() + previous.getLength() == segmentation[i].getOffset());
previous= segmentation[i];
@@ -224,9 +225,9 @@ public class ProjectionDocumentTest extends TestCase {
Fragment fragment= (Fragment) fragmention[i];
assertTrue(fragment == segment.fragment);
assertTrue(segment == fragment.segment);
- assertFalse(segmentation.length > 1 && fragment.getLength() == 0);
+ assertFalse(segmentation.length > 1 && (fragment.getLength() == 0 && i < segmentation.length - 1));
assertTrue(fragment.length == segment.length);
- if (previous != null)
+ if (previous != null && i < segmentation.length - 1)
assertFalse(previous.getOffset() + previous.getLength() == fragment.getOffset());
previous= fragment;
}
@@ -992,6 +993,29 @@ public class ProjectionDocumentTest extends TestCase {
assertMasterContents(buffer.toString());
}
+ public void test17_7() {
+ // test corner case manipulation of the segments of the slave document
+ // insert at the end of last segment of the slave document - bug 301023
+
+ createIdenticalProjection();
+ String originalSlaveContent = "";
+ try {
+ fSlaveDocument.removeMasterDocumentRange(80, 100);
+ originalSlaveContent = fSlaveDocument.get();
+ fSlaveDocument.replace(80, 0, "~");
+ } catch (BadLocationException e) {
+ assertTrue(false);
+ }
+
+ StringBuffer buffer= new StringBuffer(originalSlaveContent);
+ buffer.insert(80, "~");
+ assertSlaveContents(buffer.toString());
+
+ buffer= new StringBuffer(getOriginalMasterContents());
+ buffer.insert(180, "~");
+ assertMasterContents(buffer.toString());
+ }
+
public void test18_1() {
// test manipulations overlapping multiple segments of the slave document
// delete range overlapping two neighboring segments
@@ -1508,6 +1532,29 @@ public class ProjectionDocumentTest extends TestCase {
assertSlaveContents(buffer.toString());
}
+ public void test21_a() {
+ // test removing a range from the slave document using identical projection
+ // the removed range includes the end of the master document - see bug 301023
+
+ createIdenticalProjection();
+
+ try {
+ fSlaveDocument.removeMasterDocumentRange(80, 100);
+ } catch (BadLocationException e) {
+ assertTrue(false);
+ }
+
+ Position[] expected= {
+ new Position(0, 80),
+ new Position(180, 0)
+ };
+ assertFragmentation(expected);
+
+ StringBuffer buffer= new StringBuffer(getOriginalMasterContents());
+ buffer.delete(80, 180);
+ assertSlaveContents(buffer.toString());
+ }
+
private void assertEquals(DocumentEvent expected, DocumentEvent received) {
assertSame(expected.getDocument(), received.getDocument());
assertEquals(expected.getOffset(), received.getOffset());
diff --git a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java
index c2341d417..d1c3a0db1 100644
--- a/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java
+++ b/org.eclipse.text/projection/org/eclipse/jface/text/projection/ProjectionDocument.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Anton Leherbauer <anton.leherbauer@windriver.com> - [projection] "Backspace" key deleting something else - http://bugs.eclipse.org/301023
*******************************************************************************/
package org.eclipse.jface.text.projection;
@@ -405,8 +406,6 @@ public class ProjectionDocument extends AbstractDocument {
if (fragment.getOffset() == offsetInMaster) {
fragment.setOffset(offsetInMaster + lengthInMaster);
fragment.setLength(fragment.getLength() - lengthInMaster);
- } else if (fragment.getOffset() + fragment.getLength() == offsetInMaster + lengthInMaster) {
- fragment.setLength(fragment.getLength() - lengthInMaster);
} else {
// split fragment into three fragments, let position updater remove it
@@ -807,7 +806,7 @@ public class ProjectionDocument extends AbstractDocument {
Position[] segments= getSegments();
for (int i= 0; i < segments.length; i++) {
Segment segment= (Segment) segments[i];
- if (segment.isDeleted() || segment.getLength() == 0) {
+ if (segment.isDeleted() || (segment.getLength() == 0 && i < segments.length - 1)) {
try {
removePosition(fSegmentsCategory, segment);
fMasterDocument.removePosition(fFragmentsCategory, segment.fragment);

Back to the top