Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2009-05-01 22:58:59 -0400
committerpelder2009-05-01 22:58:59 -0400
commitb779f6ba8cf788193d8a24d69b76ee175b21ff09 (patch)
treeb9e77fb5840eeae025a6ab029f6e7c1bd56c2401
parent4b2c520c53d9be47d43fbead79bbce229d245371 (diff)
downloadorg.eclipse.jet-b779f6ba8cf788193d8a24d69b76ee175b21ff09.tar.gz
org.eclipse.jet-b779f6ba8cf788193d8a24d69b76ee175b21ff09.tar.xz
org.eclipse.jet-b779f6ba8cf788193d8a24d69b76ee175b21ff09.zip
[274715] c:deepContent tag results in incorrect ordering of c:deepIterate results
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/DocumentHelper.java41
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/DeepIterateTag.java32
2 files changed, 45 insertions, 28 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/DocumentHelper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/DocumentHelper.java
index f9fc0ef..0d99531 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/DocumentHelper.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/DocumentHelper.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: DocumentHelper.java,v 1.2 2009/03/16 14:42:30 pelder Exp $
+ * $Id: DocumentHelper.java,v 1.3 2009/05/02 02:58:59 pelder Exp $
*/
package org.eclipse.jet.internal.taglib;
@@ -38,9 +38,10 @@ public class DocumentHelper
* @param changeOffset the offset of the change occuring
* @param changeLength the original length of the changed text
* @param replacementLength the length of the new text
+ * @param fDocument
* @return <code>true</code> if the position was updated and the default updater should not be used.
*/
- public boolean update(int changeOffset, int changeLenghth, int replacementLength);
+ public boolean update(int changeOffset, int changeLength, int replacementLength, IDocument fDocument);
}
/**
@@ -50,18 +51,40 @@ public class DocumentHelper
*/
public static class InsertAfterEmptyPosition extends Position implements IPositionUpdaterOverride {
+ private boolean enableInsertBefore;
+
public InsertAfterEmptyPosition(int length)
{
super(length);
}
- public boolean update(int changeOffset, int changeLength, int replacementLength)
+ public boolean update(int changeOffset, int changeLength, int replacementLength, IDocument document)
+ {
+ // if this is an insertion (changeLength == 0) and this is a zero-length position
+ // and its happening at this position, we'll handle the update...
+ if( changeLength == 0 && this.length == 0 && changeOffset == this.offset) {
+
+ // N.B. The document has already been modified, the original document length is:
+ final int originalDocumentLength = document.getLength() - replacementLength;
+ if(this.offset == originalDocumentLength) {
+ // at the end of the buffer, don't move or expand the position
+ // NO code necessary!
+ return true;
+ } else if(enableInsertBefore) {
+ // move the position to after the insertion
+ this.offset += replacementLength;
+ return true;
+ } else {
+ return true;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public void setEnableInsertBefore(boolean enableInsertBefore)
{
- // if this position is empty, and the changes is inserting text at this position,
- // then ensure the change is inserted after this position, rather then the default
- // of shifting this position so that it is after the inserted text.
- // Note: no fields need to be updated!
- return changeLength == 0 && getLength() == 0 && changeOffset == getOffset();
+ this.enableInsertBefore = enableInsertBefore;
}
}
@@ -85,7 +108,7 @@ public class DocumentHelper
protected void adaptToReplace()
{
if(fPosition instanceof IPositionUpdaterOverride
- && ((IPositionUpdaterOverride)fPosition).update(fOffset, fLength, fReplaceLength)) {
+ && ((IPositionUpdaterOverride)fPosition).update(fOffset, fLength, fReplaceLength, fDocument)) {
return;
}
super.adaptToReplace();
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/DeepIterateTag.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/DeepIterateTag.java
index f84a66f..beb2e0b 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/DeepIterateTag.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/control/DeepIterateTag.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: DeepIterateTag.java,v 1.1 2009/03/16 14:42:30 pelder Exp $
+ * $Id: DeepIterateTag.java,v 1.2 2009/05/02 02:58:59 pelder Exp $
*/
package org.eclipse.jet.internal.taglib.control;
@@ -31,12 +31,12 @@ import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.XPathContextExtender;
import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jet.internal.taglib.DocumentHelper;
+import org.eclipse.jet.internal.taglib.DocumentHelper.InsertAfterEmptyPosition;
import org.eclipse.jet.taglib.AbstractIteratingTag;
import org.eclipse.jet.taglib.JET2TagException;
import org.eclipse.jet.taglib.TagInfo;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.w3c.dom.DOMException;
@@ -252,7 +252,7 @@ public class DeepIterateTag extends AbstractIteratingTag
{
workingOutput = (BufferedJET2Writer)getOut().newNestedContentWriter();
IDocument doc = (IDocument)workingOutput.getAdapter(IDocument.class);
- doc.addPositionCategory(INSERTION_POINT_CATEGORY);
+ DocumentHelper.installPositionCategory(doc, INSERTION_POINT_CATEGORY);
}
/* (non-Javadoc)
@@ -370,16 +370,21 @@ public class DeepIterateTag extends AbstractIteratingTag
? deepContentPositionTracker.getInsertPosition()
: null;
if(insertPosition != null) {
- replaceContent(workingOutput, insertPosition.getOffset(), 0, (BufferedJET2Writer)bodyContent);
+ replaceContent(workingOutput, (InsertAfterEmptyPosition)insertPosition, (BufferedJET2Writer)bodyContent);
} else {
workingOutput.write(bodyContent);
}
}
- private void replaceContent(BufferedJET2Writer targetWriter, int offset, int length, BufferedJET2Writer sourceWriter)
+ private void replaceContent(BufferedJET2Writer targetWriter, InsertAfterEmptyPosition insertPosition, BufferedJET2Writer sourceWriter)
{
final IDocument targetDocument = (IDocument)targetWriter.getAdapter(IDocument.class);
- targetWriter.replaceContent(offset, length, sourceWriter.getContent());
+ // save insertPosition.offset. The position replaceContent operation will update it, but we
+ // need the original offset for later on...
+ final int insertionOffset = insertPosition.offset;
+ insertPosition.setEnableInsertBefore(true);
+ targetWriter.replaceContent(insertionOffset, insertPosition.length, sourceWriter.getContent());
+ insertPosition.setEnableInsertBefore(false);
try
{
// transfer position categories, position updaters and positions
@@ -396,7 +401,7 @@ public class DeepIterateTag extends AbstractIteratingTag
for (int j = 0; j < positions.length; j++)
{
sourceDocument.removePosition(categories[i], positions[j]);
- positions[j].setOffset(positions[j].getOffset() + offset);
+ positions[j].setOffset(positions[j].getOffset() + insertionOffset);
targetDocument.addPosition(categories[i], positions[j]);
}
}
@@ -422,17 +427,6 @@ public class DeepIterateTag extends AbstractIteratingTag
// get the underlying document, and ensure it has the correct position category...
IDocument document = (IDocument)out.getAdapter(IDocument.class);
DocumentHelper.installPositionCategory(document, INSERTION_POINT_CATEGORY);
- if(!document.containsPositionCategory(INSERTION_POINT_CATEGORY)) {
- document.addPositionCategory(INSERTION_POINT_CATEGORY);
- document.addPositionUpdater(new DefaultPositionUpdater(INSERTION_POINT_CATEGORY){
- protected void adaptToReplace()
- {
- if(fOffset < fPosition.offset) {
- fPosition.offset += fReplaceLength;
- }
- }
- });
- }
// add a position
final Position position = new DocumentHelper.InsertAfterEmptyPosition(document.getLength());
@@ -454,7 +448,7 @@ public class DeepIterateTag extends AbstractIteratingTag
// remember the insert position
deepContentPositionTracker.setPosition(position);
-}
+ }
}

Back to the top