summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hiesserich2013-05-19 03:39:55 (EDT)
committer Florian Thienel2013-05-19 03:42:27 (EDT)
commita119c922f2335a66df90e6fe51b3d6ded5361d8f (patch)
tree66a857c0bf0477a4329df07418c78b9edfe3f8fe
parentc14a87d019acc008952157aae22bad1082f57237 (diff)
downloadorg.eclipse.mylyn.docs.vex-a119c922f2335a66df90e6fe51b3d6ded5361d8f.zip
org.eclipse.mylyn.docs.vex-a119c922f2335a66df90e6fe51b3d6ded5361d8f.tar.gz
org.eclipse.mylyn.docs.vex-a119c922f2335a66df90e6fe51b3d6ded5361d8f.tar.bz2
allow to insert newline into verbatim (pre) elements
https://bugs.eclipse.org/bugs/show_bug.cgi?id=407827
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DTDValidatorTest.java2
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java2
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/validator/SchemaValidatorTest.java2
-rw-r--r--org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/L2SimpleEditingTest.java44
-rw-r--r--org.eclipse.vex.core.tests/testResources/test.css8
-rw-r--r--org.eclipse.vex.core.tests/testResources/test1.dtd3
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java13
7 files changed, 65 insertions, 9 deletions
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DTDValidatorTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DTDValidatorTest.java
index dc03729..54d931e 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DTDValidatorTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/DTDValidatorTest.java
@@ -112,7 +112,7 @@ public class DTDValidatorTest {
assertValidItemsAt(doc, 4);
assertValidItemsAt(doc, 5);
assertValidItemsAt(doc, 6, "title", "para");
- assertValidItemsAt(doc, 7, "emphasis");
+ assertValidItemsAt(doc, 7, "emphasis", "pre");
assertValidItemsAt(doc, 8, "title", "para");
}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java
index aad9ff7..414a7c7 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/io/DocumentContentModelTest.java
@@ -124,6 +124,6 @@ public class DocumentContentModelTest {
assertTrue(model.isDtdAssigned());
final CMDocument dtd = model.getDTD();
assertNotNull(dtd);
- assertEquals(10, dtd.getElements().getLength());
+ assertEquals(11, dtd.getElements().getLength());
}
}
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/validator/SchemaValidatorTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/validator/SchemaValidatorTest.java
index 634ccde..9727ac4 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/validator/SchemaValidatorTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/validator/SchemaValidatorTest.java
@@ -124,7 +124,7 @@ public class SchemaValidatorTest {
@Test
public void createValidatorWithDTDPublicId() throws Exception {
final IValidator validator = new WTPVEXValidator(TEST_DTD);
- assertEquals(10, validator.getValidRootElements().size());
+ assertEquals(11, validator.getValidRootElements().size());
}
@Test
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/L2SimpleEditingTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/L2SimpleEditingTest.java
index b5ce40e..71bb480 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/L2SimpleEditingTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/L2SimpleEditingTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Florian Thienel - initial API and implementation
+ * Carsten Hiesserich - additional test for newline handling (bug 407827)
*******************************************************************************/
package org.eclipse.vex.core.internal.widget;
@@ -20,9 +21,12 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.vex.core.internal.css.StyleSheet;
+import org.eclipse.vex.core.internal.css.StyleSheetReader;
import org.eclipse.vex.core.provisional.dom.IDocumentFragment;
import org.eclipse.vex.core.provisional.dom.IElement;
+import org.eclipse.vex.core.tests.TestResources;
import org.junit.Before;
import org.junit.Test;
@@ -263,4 +267,44 @@ public class L2SimpleEditingTest {
assertFalse(widget.canInsertFragment(fragment));
widget.insertFragment(fragment);
}
+
+ @Test
+ public void hittingEnterInElement_shouldSplitElement() throws Exception {
+ final StyleSheet styleSheet = new StyleSheetReader().read(TestResources.get("test.css"));
+ widget.setDocument(createDocumentWithDTD(TEST_DTD, "section"), styleSheet);
+ rootElement = widget.getDocument().getRootElement();
+
+ widget.insertElement(TITLE);
+ widget.moveBy(1);
+ final IElement para1 = widget.insertElement(PARA);
+ widget.insertText("Hello");
+ widget.moveTo(para1.getEndOffset());
+ widget.insertText("\n");
+ assertEquals("Hello", para1.getText());
+ assertEquals(3, rootElement.children().count());
+ }
+
+ @Test
+ public void hittingEnterInPreformattedElement_shouldInsertNewline() throws Exception {
+ final StyleSheet styleSheet = new StyleSheetReader().read(TestResources.get("test.css"));
+ widget.setDocument(createDocumentWithDTD(TEST_DTD, "para"), styleSheet);
+ rootElement = widget.getDocument().getRootElement();
+
+ final IElement preElement = widget.insertElement(new QualifiedName(null, "pre"));
+ assertEquals(preElement.getEndOffset(), widget.getCaretOffset());
+ widget.insertText("Line1");
+ widget.insertText("\n");
+ assertEquals(1, rootElement.children().count());
+ assertEquals("Line1\n", preElement.getText());
+ }
+
+ @Test
+ public void insertingTextWithNewlineToPreformattedElement_shouldInsertNewline() throws Exception {
+ final StyleSheet styleSheet = new StyleSheetReader().read(TestResources.get("test.css"));
+ widget.setDocument(createDocumentWithDTD(TEST_DTD, "para"), styleSheet);
+ final IElement preElement = widget.insertElement(new QualifiedName(null, "pre"));
+ assertEquals(preElement.getEndOffset(), widget.getCaretOffset());
+ widget.insertText("Line1\nLine2");
+ assertEquals("Line1\nLine2", preElement.getText());
+ }
}
diff --git a/org.eclipse.vex.core.tests/testResources/test.css b/org.eclipse.vex.core.tests/testResources/test.css
index 9a83031..5bf85c5 100644
--- a/org.eclipse.vex.core.tests/testResources/test.css
+++ b/org.eclipse.vex.core.tests/testResources/test.css
@@ -15,6 +15,14 @@ block {
display: block;
}
+section {
+ display: block;
+}
+
+para {
+ display: block;
+}
+
pre {
display: block;
white-space: pre;
diff --git a/org.eclipse.vex.core.tests/testResources/test1.dtd b/org.eclipse.vex.core.tests/testResources/test1.dtd
index 3633edd..f1e5607 100644
--- a/org.eclipse.vex.core.tests/testResources/test1.dtd
+++ b/org.eclipse.vex.core.tests/testResources/test1.dtd
@@ -3,12 +3,13 @@
<!ELEMENT any ANY>
<!ELEMENT empty EMPTY>
<!ELEMENT section (title?, para+)>
-<!ELEMENT para (#PCDATA | emphasis)*>
+<!ELEMENT para (#PCDATA | emphasis | pre)*>
<!ELEMENT emphasis (#PCDATA)>
<!ELEMENT one-kind-of-child (section+)>
<!ELEMENT document (title?, preface, section+, index)>
<!ELEMENT preface (para+)>
<!ELEMENT index (para+)>
+<!ELEMENT pre (#PCDATA)>
<!-- a dummy attribute, just to make sure attribute def serialization is OK -->
<!ATTLIST section
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
index ddd7ab4..5e4be04 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
@@ -11,6 +11,7 @@
* Holger Voormann - bug 315914: content assist should only show elements
* valid in the current context
* Carsten Hiesserich - handling of elements within comments (bug 407801)
+ * Carsten Hiesserich - allow insertion of newline into pre elements (bug 407827)
*******************************************************************************/
package org.eclipse.vex.core.internal.widget;
@@ -847,14 +848,16 @@ public class VexWidgetImpl implements IVexWidget {
beginWork();
int i = 0;
for (;;) {
- final int j = text.indexOf('\n', i);
- if (j == -1) {
+ final int nextLineBreak = text.indexOf('\n', i);
+ if (nextLineBreak == -1) {
break;
}
- applyEdit(new InsertTextEdit(document, getCaretOffset(), text.substring(i, j)), getCaretOffset());
- this.moveTo(getCaretOffset() + j - i);
+ if (nextLineBreak - i > 0) {
+ applyEdit(new InsertTextEdit(document, getCaretOffset(), text.substring(i, nextLineBreak)), getCaretOffset());
+ }
+ this.moveTo(getCaretOffset() + nextLineBreak - i);
split();
- i = j + 1;
+ i = nextLineBreak + 1;
}
if (i < text.length()) {