/** * @return int * @param node org.eclipse.wst.css.core.model.interfaces.ICSSNode * @param insertPos int */ public int getLengthToReformatAfter(ICSSNode node, int insertPos) { if (node == null) return 0; IndexedRegion nnode = (IndexedRegion) node; if (insertPos < 0 || !nnode.contains(insertPos)) return 0; IStructuredDocumentRegion flatNode = node.getOwnerDocument() .getModel() .getStructuredDocument() .getRegionAtCharacterOffset(insertPos); if (flatNode == null) return 0; ITextRegion region = flatNode.getRegionAtCharacterOffset(insertPos); if (region == null) return 0; RegionIterator it = new RegionIterator(flatNode, region); boolean found = false; while (it.hasNext()) { region = it.next(); // 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 = (found ? it.getStructuredDocumentRegion().getStartOffset(region) : it.getStructuredDocumentRegion().getTextEndOffset(region)) - insertPos; return (pos >= 0) ? pos : 0; }
private void checkSemiColon() { fAppendSemiColon = false; ITextRegion targetRegion = fContext.getTargetRegion(); if (targetRegion != null && targetRegion.getType() != CSSRegionContexts.CSS_DECLARATION_DELIMITER) { // find trailing ":" or ";" // if ":" before ";" is found, add ";" RegionIterator iterator = fContext.getRegionIterator(); IStructuredDocumentRegion container = iterator.getStructuredDocumentRegion(); while (iterator.hasNext()) { ITextRegion region = iterator.next(); if (iterator.getStructuredDocumentRegion() != container) { break; } if (region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) { fAppendSemiColon = true; break; } } if (!fAppendSemiColon) { // second chance: // leading IStructuredDocumentRegion is not ";" IStructuredDocumentRegion nextStructuredDocumentRegion = CSSUtil.findNextSignificantNode(container); if (CSSUtil.getStructuredDocumentRegionType(nextStructuredDocumentRegion) != CSSRegionContexts.CSS_DECLARATION_DELIMITER) { fAppendSemiColon = true; } } } }
private void addSemiColon(List candidates) { ICSSNode targetNode = fContext.getTargetNode(); if (targetNode instanceof ICSSStyleDeclItem) { ICSSNode firstChild = targetNode.getFirstChild(); if (firstChild == null) { return; } if (firstChild instanceof IndexedRegion) { int startOffset = ((IndexedRegion) firstChild).getStartOffset(); if (fContext.getCursorPos() <= startOffset) { return; } } } boolean bAddCloser = false; ITextRegion targetRegion = fContext.getTargetRegion(); if (targetRegion != null && targetRegion.getType() != CSSRegionContexts.CSS_DECLARATION_DELIMITER) { // find trailing ":" or ";" // if ":" before ";" is found, add ";" RegionIterator iterator = fContext.getRegionIterator(); IStructuredDocumentRegion container = iterator.getStructuredDocumentRegion(); while (iterator.hasNext()) { ITextRegion region = iterator.next(); if (iterator.getStructuredDocumentRegion() != container) { break; } if (region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) { bAddCloser = true; break; } } if (!bAddCloser) { // second chance: // leading IStructuredDocumentRegion is not ";" IStructuredDocumentRegion nextStructuredDocumentRegion = CSSUtil.findNextSignificantNode(container); if (CSSUtil.getStructuredDocumentRegionType(nextStructuredDocumentRegion) != CSSRegionContexts.CSS_DECLARATION_DELIMITER) { bAddCloser = true; } } } if (bAddCloser) { CSSCACandidate item = new CSSCACandidate(); String text = fContext.getTextToReplace() + ";"; // $NON-NLS-1$ item.setReplacementString(text); item.setCursorPosition(text.length()); item.setDisplayString(";"); // $NON-NLS-1$ item.setImageType(null); candidates.add(item); } }
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; }