diff options
author | nsandonato | 2009-10-21 21:37:11 +0000 |
---|---|---|
committer | nsandonato | 2009-10-21 21:37:11 +0000 |
commit | 550035b9801a27f413d4252fec3770ea6678fe56 (patch) | |
tree | 91cb566e568cfa869f0e2652d41a81904bb05211 /bundles/org.eclipse.wst.css.ui | |
parent | ab2eb8ae7389183427c9ca851737b8d789b960d1 (diff) | |
download | webtools.sourceediting-550035b9801a27f413d4252fec3770ea6678fe56.tar.gz webtools.sourceediting-550035b9801a27f413d4252fec3770ea6678fe56.tar.xz webtools.sourceediting-550035b9801a27f413d4252fec3770ea6678fe56.zip |
[289842] [projection] Upgrades for new comment folding to act more like JDT
Diffstat (limited to 'bundles/org.eclipse.wst.css.ui')
2 files changed, 69 insertions, 26 deletions
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/projection/CSSFoldingStrategy.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/projection/CSSFoldingStrategy.java index 8ddfb8e2d9..2811691081 100644 --- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/projection/CSSFoldingStrategy.java +++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/projection/CSSFoldingStrategy.java @@ -15,12 +15,9 @@ import java.util.Iterator; import java.util.List; import org.eclipse.jface.text.Position; -import org.eclipse.wst.css.core.internal.document.CSSStructuredDocumentRegionContainer; -import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem; +import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule; import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; import org.eclipse.wst.sse.ui.internal.projection.AbstractStructuredFoldingStrategy; -import org.w3c.dom.css.CSSStyleRule; -import org.w3c.dom.css.CSSStyleSheet; /** * A folding strategy for CSS structured documents. @@ -36,29 +33,15 @@ public class CSSFoldingStrategy extends AbstractStructuredFoldingStrategy { super(); } - /* - * (non-Javadoc) + /** * @see org.eclipse.wst.sse.ui.internal.projection.AbstractFoldingStrategy#calcNewFoldPosition(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) */ protected Position calcNewFoldPosition(IndexedRegion indexedRegion) { Position newPos = null; - //don't want a fold region for the entire sheet - if(indexedRegionValidType(indexedRegion)) { - CSSStructuredDocumentRegionContainer node = (CSSStructuredDocumentRegionContainer)indexedRegion; - - int start = node.getStartOffset(); - //so that multi-line CSS selector text does not get folded - if(node instanceof CSSStyleRule) { - CSSStyleRule rule = (CSSStyleRule)node; - start += rule.getSelectorText().length(); - } - - //-1 for the end brace - int length = node.getEndOffset()-start-1; - - if(length >= 0) { - newPos = new Position(start,length); - } + + //only want to fold regions with a valid range + if(indexedRegionValidType(indexedRegion) && indexedRegion.getStartOffset() >= 0 && indexedRegion.getLength() >= 0) { + newPos = new CSSRuleFoldingPosition(indexedRegion); } return newPos; } @@ -96,11 +79,10 @@ public class CSSFoldingStrategy extends AbstractStructuredFoldingStrategy { } } - /* - * (non-Javadoc) + /** * @see org.eclipse.wst.sse.ui.internal.projection.AbstractFoldingStrategy#indexedRegionValidType(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) */ protected boolean indexedRegionValidType(IndexedRegion indexedRegion) { - return (!(indexedRegion instanceof CSSStyleSheet || indexedRegion instanceof ICSSStyleDeclItem)); + return (indexedRegion instanceof ICSSStyleRule); } } diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/projection/CSSRuleFoldingPosition.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/projection/CSSRuleFoldingPosition.java new file mode 100644 index 0000000000..dfc0984437 --- /dev/null +++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/projection/CSSRuleFoldingPosition.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2009 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * + *******************************************************************************/ +package org.eclipse.wst.css.ui.internal.projection; + +import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; +import org.eclipse.wst.sse.ui.internal.projection.AbstractStructuredFoldingPosition; +import org.w3c.dom.css.CSSStyleRule; + +/** + * An {@link AbstractStructuredFoldingPosition} used to cover CSS regions + */ +public class CSSRuleFoldingPosition extends AbstractStructuredFoldingPosition { + + /** + * the region that will be folded + */ + private IndexedRegion fRegion; + + /** + * Creates a folding position that covers {@link IndexedRegion}s + * in a CSS document + * + * @param region the {@link IndexedRegion} that this folding position covers + */ + public CSSRuleFoldingPosition(IndexedRegion region) { + super(region.getStartOffset(), region.getLength()); + this.fRegion = region; + } + + /** + * @see org.eclipse.wst.sse.ui.internal.projection.AbstractStructuredFoldingPosition#getStartOffset() + */ + protected int getStartOffset() { + int startOffset = fRegion.getStartOffset(); + + //so that multi-line CSS selector text does not get folded + if(this.fRegion instanceof CSSStyleRule) { + CSSStyleRule rule = (CSSStyleRule)this.fRegion; + startOffset += rule.getSelectorText().length(); + } + + return startOffset; + } + + /** + * @see org.eclipse.wst.sse.ui.internal.projection.AbstractStructuredFoldingPosition#getEndOffset() + */ + protected int getEndOffset() { + return fRegion.getEndOffset(); + } + +}
\ No newline at end of file |