/**
   * @return int
   * @param node org.eclipse.wst.css.core.model.interfaces.ICSSNode
   * @param insertPos int
   */
  public int getLengthToReformatBefore(ICSSNode node, int insertPos) {
    if (node == null) return 0;
    IndexedRegion nnode = (IndexedRegion) node;
    if (insertPos <= 0 || !nnode.contains(insertPos - 1)) return 0;

    IStructuredDocumentRegion flatNode =
        node.getOwnerDocument()
            .getModel()
            .getStructuredDocument()
            .getRegionAtCharacterOffset(insertPos - 1);
    if (flatNode == null) return 0;
    ITextRegion region = flatNode.getRegionAtCharacterOffset(insertPos - 1);
    if (region == null) return 0;
    RegionIterator it = new RegionIterator(flatNode, region);
    boolean found = false;
    while (it.hasPrev()) {
      region = it.prev();
      // if (region.getType() != CSSRegionContexts.CSS_S &&
      // region.getType() != CSSRegionContexts.CSS_DELIMITER &&
      // region.getType() !=
      // CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
      if (region.getType() != CSSRegionContexts.CSS_S) {
        found = true;
        break;
      }
    }
    int pos =
        insertPos
            - (found
                ? it.getStructuredDocumentRegion().getTextEndOffset(region)
                : it.getStructuredDocumentRegion().getStartOffset(region));
    // flatNode = it.getStructuredDocumentRegion();
    // if (found) {
    // if (region.getLength() != region.getTextLength()) {
    // pos = insertPos - flatNode.getTextEndOffset(region);
    // } else {
    // pos = insertPos - flatNode.getEndOffset(region);
    // }
    // } else {
    // pos = insertPos - flatNode.getStartOffset(region);
    // }
    return (pos >= 0) ? pos : 0;
  }
 protected CompoundRegion[] getOutsideRegions(IStructuredDocument model, IRegion reg) {
   CompoundRegion[] ret = new CompoundRegion[2];
   RegionIterator it = new RegionIterator(model, reg.getOffset());
   it.prev();
   if (it.hasPrev()) {
     ITextRegion textRegion = it.prev();
     IStructuredDocumentRegion documentRegion = it.getStructuredDocumentRegion();
     ret[0] = new CompoundRegion(documentRegion, textRegion);
   } else {
     ret[0] = null;
   }
   it.reset(model, reg.getOffset() + reg.getLength());
   if (it.hasNext()) {
     ITextRegion textRegion = it.next();
     IStructuredDocumentRegion documentRegion = it.getStructuredDocumentRegion();
     ret[1] = new CompoundRegion(documentRegion, textRegion);
   } else {
     ret[1] = null;
   }
   return ret;
 }