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);
}
}
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);
}
}
}
}
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;
}
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;
}
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;
}
Aggregations