move cursor right into the content if there is inline content

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
index bbcfc5f..5d65c6a 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
@@ -80,10 +80,19 @@
 		return structuralNodeReference;
 	}
 
+	public static StructuralNodeReference nodeReferenceWithInlineContent(final INode node, final IStructuralBox component) {
+		final StructuralNodeReference structuralNodeReference = new StructuralNodeReference();
+		structuralNodeReference.setNode(node);
+		structuralNodeReference.setContainsInlineContent(true);
+		structuralNodeReference.setComponent(component);
+		return structuralNodeReference;
+	}
+
 	public static StructuralNodeReference nodeReferenceWithText(final INode node, final IStructuralBox component) {
 		final StructuralNodeReference structuralNodeReference = new StructuralNodeReference();
 		structuralNodeReference.setNode(node);
 		structuralNodeReference.setCanContainText(true);
+		structuralNodeReference.setContainsInlineContent(true);
 		structuralNodeReference.setComponent(component);
 		return structuralNodeReference;
 	}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralNodeReference.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralNodeReference.java
index 9621813..95a8379 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralNodeReference.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralNodeReference.java
@@ -37,6 +37,7 @@
 
 	private INode node;
 	private boolean canContainText;
+	private boolean containsInlineContent;
 
 	@Override
 	public void setParent(final IBox parent) {
@@ -137,6 +138,14 @@
 		return canContainText;
 	}
 
+	public void setContainsInlineContent(final boolean containsInlineContent) {
+		this.containsInlineContent = containsInlineContent;
+	}
+
+	public boolean containsInlineContent() {
+		return containsInlineContent;
+	}
+
 	@Override
 	public void layout(final Graphics graphics) {
 		if (component == null) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/MoveDown.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/MoveDown.java
index 9dbc4a3..f4360e3 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/MoveDown.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/MoveDown.java
@@ -51,9 +51,9 @@
 		if (isAtStartOfBoxWithChildren(currentOffset, currentBox)) {
 			final IContentBox firstChild = getFirstContentBoxChild(currentBox);
 			if (firstChild != null) {
-				if (canContainText(currentBox)) {
+				if (containsInlineContent(currentBox)) {
 					return findOffsetInNextBoxBelow(graphics, currentOffset, firstChild, preferredX, hotArea.getY() + hotArea.getHeight() - 1);
-				} else if (canContainText(firstChild)) {
+				} else if (containsInlineContent(firstChild)) {
 					return findOffsetInNextBoxBelow(graphics, currentOffset, firstChild, preferredX, currentBox.getAbsoluteTop() - 1);
 				} else {
 					return firstChild.getStartOffset();
@@ -86,16 +86,16 @@
 		});
 	}
 
-	private static boolean canContainText(final IContentBox box) {
+	private static boolean containsInlineContent(final IContentBox box) {
 		return box.accept(new BaseBoxVisitorWithResult<Boolean>(false) {
 			@Override
 			public Boolean visit(final StructuralNodeReference box) {
-				return box.canContainText();
+				return box.containsInlineContent();
 			}
 
 			@Override
 			public Boolean visit(final InlineNodeReference box) {
-				return box.canContainText();
+				return true;
 			}
 
 			@Override
@@ -212,7 +212,7 @@
 
 		final IContentBox childBelow = findClosestContentBoxChildBelow(parent, x, y);
 		if (childBelow == null) {
-			if (canContainText(parent)) {
+			if (containsInlineContent(parent)) {
 				return findNextContentBoxBelow(parent, x, y);
 			}
 			return parent;
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/MoveUp.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/MoveUp.java
index 6d2c6df..b774630 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/MoveUp.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/cursor/MoveUp.java
@@ -58,9 +58,9 @@
 		if (isAtEndOfBoxWithChildren(currentOffset, currentBox)) {
 			final IContentBox lastChild = getLastContentBoxChild(currentBox);
 			if (lastChild != null) {
-				if (canContainText(currentBox)) {
+				if (containsInlineContent(currentBox)) {
 					return findOffsetInNextBoxAbove(graphics, currentOffset, lastChild, preferredX, hotArea.getY());
-				} else if (canContainText(lastChild)) {
+				} else if (containsInlineContent(lastChild)) {
 					return findOffsetInNextBoxAbove(graphics, currentOffset, lastChild, preferredX, currentBox.getAbsoluteTop() + currentBox.getHeight());
 				} else {
 					return lastChild.getEndOffset();
@@ -106,16 +106,16 @@
 		});
 	}
 
-	private static boolean canContainText(final IContentBox box) {
+	private static boolean containsInlineContent(final IContentBox box) {
 		return box.accept(new BaseBoxVisitorWithResult<Boolean>(false) {
 			@Override
 			public Boolean visit(final StructuralNodeReference box) {
-				return box.canContainText();
+				return box.containsInlineContent();
 			}
 
 			@Override
 			public Boolean visit(final InlineNodeReference box) {
-				return box.canContainText();
+				return true;
 			}
 
 			@Override
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
index 8983e14..6744928 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
@@ -12,6 +12,7 @@
 
 import static org.eclipse.vex.core.internal.boxes.BoxFactory.inlineContainer;
 import static org.eclipse.vex.core.internal.boxes.BoxFactory.nodeReference;
+import static org.eclipse.vex.core.internal.boxes.BoxFactory.nodeReferenceWithInlineContent;
 import static org.eclipse.vex.core.internal.boxes.BoxFactory.nodeReferenceWithText;
 import static org.eclipse.vex.core.internal.boxes.BoxFactory.rootBox;
 import static org.eclipse.vex.core.internal.boxes.BoxFactory.verticalBlock;
@@ -199,17 +200,23 @@
 			@Override
 			public IStructuralBox visit(final IElement element) {
 				final boolean mayContainText = mayContainText(element);
+				final boolean containsInlineContent = containsInlineContent(childrenResults);
+
 				final IStructuralBox content;
 				if (isEmptyElement(element)) {
 					content = visualizeEmptyElement(styles, element);
-				} else if (mayContainText || containsInlineContent(childrenResults)) {
-					content = visualizeInlineNodeContent(element, styles, childrenResults, paragraph(styles));
 				} else {
-					content = visualizeChildrenAsStructure(childrenResults, verticalBlock());
+					if (mayContainText || containsInlineContent) {
+						content = visualizeInlineNodeContent(element, styles, childrenResults, paragraph(styles));
+					} else {
+						content = visualizeChildrenAsStructure(childrenResults, verticalBlock());
+					}
 				}
 
 				if (mayContainText) {
 					return nodeReferenceWithText(element, surroundWithPseudoElements(frame(content, styles), element, styles));
+				} else if (containsInlineContent) {
+					return nodeReferenceWithInlineContent(element, surroundWithPseudoElements(frame(content, styles), element, styles));
 				} else {
 					return nodeReference(element, surroundWithPseudoElements(frame(content, styles), element, styles));
 				}