Search in sources :

Example 86 with IndexedRegion

use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForDeclarationValue method addSemiColon.

/**
 */
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();
        // $NON-NLS-1$
        String text = fContext.getTextToReplace() + ";";
        item.setReplacementString(text);
        item.setCursorPosition(text.length());
        // $NON-NLS-1$
        item.setDisplayString(";");
        item.setImageType(null);
        candidates.add(item);
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.css.core.internal.util.RegionIterator) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 87 with IndexedRegion

use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForDeclarationValue method addImportant.

private void addImportant(List candidates) {
    ICSSNode targetNode = fContext.getTargetNode();
    while (targetNode instanceof ICSSPrimitiveValue) {
        targetNode = targetNode.getParentNode();
    }
    if (!(targetNode instanceof ICSSStyleDeclItem)) {
        return;
    }
    // 1. has no priority region
    // 2. cursor position is after of last child
    // 3. normal isMatch method
    String priority = ((ICSSStyleDeclItem) targetNode).getPriority();
    if (priority == null || priority.length() == 0) {
        ICSSNode lastChild = targetNode.getLastChild();
        if (lastChild instanceof IndexedRegion) {
            int startOffset = ((IndexedRegion) lastChild).getStartOffset();
            // int endOffset = ((IndexedRegion)lastChild).getEndOffset();
            if (startOffset < fContext.getCursorPos() && isMatch(IMPORTANT)) {
                CSSCACandidate item = new CSSCACandidate();
                item.setReplacementString(IMPORTANT);
                item.setCursorPosition(IMPORTANT.length());
                item.setDisplayString(IMPORTANT);
                item.setImageType(CSSImageType.VALUE_STRING);
                appendSemiColon(item);
                candidates.add(item);
            }
        }
    }
}
Also used : ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 88 with IndexedRegion

use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.

the class StructuredSelectNextHandler method getNewSelectionRegion.

protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
    Region newRegion = null;
    if (indexedRegion instanceof ICSSNode) {
        ICSSNode cursorNode = (ICSSNode) indexedRegion;
        Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
        int currentOffset = textSelection.getOffset();
        int currentEndOffset = currentOffset + textSelection.getLength();
        if (cursorNodeRegion.getOffset() >= currentOffset && cursorNodeRegion.getOffset() <= currentEndOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset) {
            ICSSNode newNode = cursorNode.getNextSibling();
            if (newNode == null) {
                newNode = cursorNode.getParentNode();
                if (newNode instanceof IndexedRegion) {
                    IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                    newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
                }
            } else {
                if (newNode instanceof IndexedRegion) {
                    IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                    newRegion = new Region(currentOffset, newIndexedRegion.getEndOffset() - currentOffset);
                }
            }
        } else
            newRegion = cursorNodeRegion;
    }
    return newRegion;
}
Also used : Region(org.eclipse.jface.text.Region) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 89 with IndexedRegion

use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.

the class CSSContentAssistContext method initializeTargetNode.

/**
 */
private void initializeTargetNode() {
    if (fCursorPos == 0) {
        fTargetNode = fModel.getDocument();
        return;
    }
    // find edge of tree node
    ICSSNode cursorNode = getNodeAt(fCursorPos);
    if (cursorNode == null) {
        // end of document
        cursorNode = fModel.getDocument();
    }
    ICSSNode node = null;
    IStructuredDocumentRegion flatNode = fStructuredDocument.getRegionAtCharacterOffset(fCursorPos - 1);
    while (flatNode != null && (node = getNodeAt(flatNode.getStartOffset())) == cursorNode && ((IndexedRegion) node).getStartOffset() != flatNode.getStartOffset()) {
        flatNode = flatNode.getPrevious();
    }
    if (flatNode == null) {
        // top of document
        fTargetNode = (node == null) ? fModel.getDocument() : node;
        return;
    }
    // BBBBBBBBBB cursorNode:A , node:B -> target is A
    if (cursorNode != null) {
        for (ICSSNode parent = cursorNode.getParentNode(); parent != null; parent = parent.getParentNode()) {
            if (parent == cursorNode) {
                fTargetNode = cursorNode;
                return;
            }
        }
    }
    // v<--|
    // AAA
    // BBBBBBBBBB cursorNode:B , node:A -> depend on A's node type
    short nodeType = node.getNodeType();
    if (nodeType == ICSSNode.STYLEDECLITEM_NODE || nodeType == ICSSNode.CHARSETRULE_NODE || nodeType == ICSSNode.IMPORTRULE_NODE) {
        String type = CSSUtil.getStructuredDocumentRegionType(flatNode);
        if (type == CSSRegionContexts.CSS_DELIMITER || type == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
            fTargetNode = node.getParentNode();
        } else {
            fTargetNode = node;
        }
    // fTargetNode = (bOverSemiColon) ? node.getParentNode() : node;
    } else if (CSSUtil.getStructuredDocumentRegionType(flatNode) == CSSRegionContexts.CSS_RBRACE) {
        fTargetNode = node.getParentNode();
    } else {
        fTargetNode = node;
    }
    return;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 90 with IndexedRegion

use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.

the class SelectionCollector method preNode.

/**
 */
protected short preNode(ICSSNode node) {
    IndexedRegion iNode = (IndexedRegion) node;
    if (iNode.getStartOffset() <= end && start < iNode.getEndOffset()) {
        if (node.getNodeType() != ICSSNode.STYLESHEET_NODE) {
            IndexedRegion iFirstChild = (IndexedRegion) node.getFirstChild();
            IndexedRegion iLastChild = (IndexedRegion) node.getLastChild();
            if (iFirstChild == null || start < iFirstChild.getStartOffset() || iLastChild.getEndOffset() <= end)
                selectedNodes.add(node);
        }
        return TRAV_CONT;
    }
    if (iNode.getStartOffset() > end)
        return TRAV_STOP;
    else
        return TRAV_PRUNE;
}
Also used : IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Aggregations

IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)148 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)33 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)32 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)31 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)27 Node (org.w3c.dom.Node)27 Region (org.eclipse.jface.text.Region)21 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)21 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)21 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)20 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)17 ArrayList (java.util.ArrayList)11 List (java.util.List)11 ITextSelection (org.eclipse.jface.text.ITextSelection)11 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)10 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)8 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)8 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)8 Preferences (org.eclipse.core.runtime.Preferences)7 IDocument (org.eclipse.jface.text.IDocument)7