aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hiesserich2013-06-21 14:05:59 (EDT)
committerFlorian Thienel2013-06-21 14:05:59 (EDT)
commitffaf9cc7752fa5b2f65d777f63f3c7f0af8ea799 (patch)
treeb4c61b29c2aa6eab17814f6feb6f3f151e756db1
parentc094e52672e4d2efc6ff28bf012baa51364c6aca (diff)
downloadorg.eclipse.mylyn.docs.vex-ffaf9cc7752fa5b2f65d777f63f3c7f0af8ea799.zip
org.eclipse.mylyn.docs.vex-ffaf9cc7752fa5b2f65d777f63f3c7f0af8ea799.tar.gz
org.eclipse.mylyn.docs.vex-ffaf9cc7752fa5b2f65d777f63f3c7f0af8ea799.tar.bz2
handle block splitting when cursor is right before inline element
https://bugs.eclipse.org/bugs/show_bug.cgi?id=410659
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/L1DeletionTests.java82
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/tests/VEXCoreTestSuite.java10
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java23
3 files changed, 101 insertions, 14 deletions
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/L1DeletionTests.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/L1DeletionTests.java
new file mode 100644
index 0000000..017d081
--- /dev/null
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/L1DeletionTests.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Carsten Hiesserich 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Carsten Hiesserich - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.core.internal.dom;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.vex.core.provisional.dom.ContentRange;
+import org.eclipse.vex.core.provisional.dom.DocumentValidationException;
+import org.eclipse.vex.core.provisional.dom.IDocument;
+import org.eclipse.vex.core.provisional.dom.IElement;
+import org.junit.Before;
+import org.junit.Test;
+
+public class L1DeletionTests {
+
+ private IDocument document;
+ private IElement child;
+ private IElement grandchild;
+
+ @Before
+ public void setUp() throws Exception {
+ document = new Document(new QualifiedName(null, "root"));
+ child = document.insertElement(2, new QualifiedName(null, "child"));
+ document.insertText(child.getEndOffset(), "12345");
+ grandchild = document.insertElement(child.getEndOffset(), new QualifiedName(null, "grandchild"));
+ document.insertText(grandchild.getEndOffset(), "ABCDEF");
+ document.insertText(child.getEndOffset(), "67890");
+ }
+
+ @Test
+ public void shouldDeleteRangeWithTextOnly() throws Exception {
+ document.delete(new ContentRange(grandchild.getStartOffset() + 2, grandchild.getEndOffset() - 2));
+ assertEquals("Text content after deletion", "AF", grandchild.getText());
+ }
+
+ @Test
+ public void shouldDeleteChildWhenRangeEqualsChildRange() throws Exception {
+ document.delete(new ContentRange(grandchild.getStartOffset(), grandchild.getEndOffset()));
+ assertEquals("Text content after deletion", "1234567890", child.getText());
+ assertTrue("Child should be deleted", child.children().withoutText().count() == 0);
+ }
+
+ @Test
+ public void shouldDeleteChildWhenRangeStartsAtChildStartPos() throws Exception {
+ document.delete(new ContentRange(grandchild.getStartOffset(), child.getEndOffset() - 1));
+ assertEquals("Text content after deletion", "12345", child.getText());
+ assertTrue("Child should be deleted", child.children().withoutText().count() == 0);
+ }
+
+ @Test
+ public void shouldDeleteChildWhenRangeEndsAtChildEndPos() throws Exception {
+ document.delete(new ContentRange(child.getStartOffset() + 1, grandchild.getEndOffset()));
+ assertEquals("Text content after deletion", "67890", child.getText());
+ assertTrue("Child should be deleted", child.children().withoutText().count() == 0);
+ }
+
+ @Test(expected = DocumentValidationException.class)
+ public void shouldNotDeleteUnbalancedRange() throws Exception {
+ document.delete(new ContentRange(grandchild.getStartOffset() + 1, child.getEndOffset() - 1));
+ }
+
+ @Test(expected = DocumentValidationException.class)
+ public void shouldNotDeleteUnbalancedRangeWhenRangeEndsAtEndOffset() throws Exception {
+ document.delete(new ContentRange(grandchild.getStartOffset() + 1, grandchild.getEndOffset()));
+ }
+
+ @Test(expected = DocumentValidationException.class)
+ public void shouldNotDeleteUnbalancedRangeWhenRangeStartsAtStartOffset() throws Exception {
+ document.delete(new ContentRange(grandchild.getStartOffset(), grandchild.getEndOffset() - 1));
+ System.out.println(document);
+ }
+}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/tests/VEXCoreTestSuite.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/tests/VEXCoreTestSuite.java
index 924fa74..7d42f3d 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/tests/VEXCoreTestSuite.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/tests/VEXCoreTestSuite.java
@@ -32,6 +32,7 @@ import org.eclipse.vex.core.internal.dom.DocumentFragmentTest;
import org.eclipse.vex.core.internal.dom.DocumentTest;
import org.eclipse.vex.core.internal.dom.GapContentTest;
import org.eclipse.vex.core.internal.dom.L1CommentHandlingTest;
+import org.eclipse.vex.core.internal.dom.L1DeletionTests;
import org.eclipse.vex.core.internal.dom.L1ElementHandlingTest;
import org.eclipse.vex.core.internal.dom.L1FragmentHandlingTest;
import org.eclipse.vex.core.internal.dom.L1TextHandlingTest;
@@ -63,10 +64,11 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({ FilterIteratorTest.class, FirstNIteratorTest.class, AfterNIteratorTest.class, AxisTest.class, NamespaceStackTest.class, NamespaceTest.class, DocumentReaderTest.class,
DocumentContentModelTest.class, SchemaValidatorTest.class, CssTest.class, BatikBehaviorTest.class, ContentRangeTest.class, BasicNodeTest.class, ParentTest.class, DocumentTest.class,
- L1TextHandlingTest.class, L1CommentHandlingTest.class, L1ElementHandlingTest.class, L1FragmentHandlingTest.class, DocumentFragmentTest.class, CopyVisitorTest.class, DeepCopyTest.class,
- PropertyTest.class, RuleTest.class, BlockElementBoxTest.class, ImageBoxTest.class, DocumentWriterTest.class, DTDValidatorTest.class, GapContentTest.class, SpaceNormalizerTest.class,
- TextWrapperTest.class, TestBlockElementBox.class, TestBlocksInInlines.class, TestDocumentTextBox.class, TestStaticTextBox.class, TableLayoutTest.class, LayoutTestSuite.class,
- ListenerListTest.class, XMLFragmentTest.class, VexWidgetTest.class, L2SimpleEditingTest.class, L2SelectionTest.class, L2CommentEditingTest.class, L2XmlInsertionTest.class
+ L1TextHandlingTest.class, L1CommentHandlingTest.class, L1ElementHandlingTest.class, L1FragmentHandlingTest.class, L1DeletionTests.class, DocumentFragmentTest.class, CopyVisitorTest.class,
+ DeepCopyTest.class, PropertyTest.class, RuleTest.class, BlockElementBoxTest.class, ImageBoxTest.class, DocumentWriterTest.class, DTDValidatorTest.class, GapContentTest.class,
+ SpaceNormalizerTest.class, TextWrapperTest.class, TestBlockElementBox.class, TestBlocksInInlines.class, TestDocumentTextBox.class, TestStaticTextBox.class, TableLayoutTest.class,
+ LayoutTestSuite.class, ListenerListTest.class, XMLFragmentTest.class, VexWidgetTest.class, L2SimpleEditingTest.class, L2SelectionTest.class, L2CommentEditingTest.class,
+ L2XmlInsertionTest.class
})
public class VEXCoreTestSuite {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
index 27f655c..82d9bd5 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
@@ -9,7 +9,7 @@
* John Krasnay - initial API and implementation
* Igor Jacy Lino Campista - Java 5 warnings fixed (bug 311325)
* Florian Thienel - refactoring to full fledged DOM
- * Carsten Hiesserich - handling of elements within comments (bug 407801)
+ * Carsten Hiesserich - bug fixes (bug 407801, 410659)
*******************************************************************************/
package org.eclipse.vex.core.internal.dom;
@@ -400,17 +400,20 @@ public class Document extends Parent implements IDocument {
}
public void delete(final ContentRange range) throws DocumentValidationException {
- final IParent surroundingParent = getParentAt(range.getStartOffset());
- final IParent parentAtEndOffset = getParentAt(range.getEndOffset());
- Assert.isTrue(surroundingParent == parentAtEndOffset, MessageFormat.format("Range {0} for deletion is unbalanced: {1} -> {2}", range, surroundingParent, parentAtEndOffset));
-
- final Parent parentForDeletion;
- if (range.equals(surroundingParent.getRange())) {
- parentForDeletion = (Parent) surroundingParent.getParent();
- } else {
- parentForDeletion = (Parent) surroundingParent;
+ IParent surroundingParent = getParentAt(range.getStartOffset());
+ if (range.getStartOffset() == surroundingParent.getStartOffset()) {
+ if (surroundingParent.getEndOffset() > range.getEndOffset()) {
+ throw new DocumentValidationException(MessageFormat.format("Range for deletion is unbalanced (Node {1} is not completely enclosed)", surroundingParent));
+ }
+ surroundingParent = surroundingParent.getParent();
+ }
+
+ if (surroundingParent.getEndOffset() <= range.getEndOffset()) {
+ throw new DocumentValidationException(MessageFormat.format("Range for deletion is unbalanced (Range exceeds end offset of node {1})", surroundingParent));
}
+ final Parent parentForDeletion = (Parent) surroundingParent;
+
final boolean deletionIsValid = parentForDeletion.accept(new BaseNodeVisitorWithResult<Boolean>(true) {
@Override
public Boolean visit(final IDocument document) {