use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class StructuredSelectNextXMLHandler method getNewSelectionRegion2.
/**
* This method was separated out from getNewSelectionRegion2 because the
* code in here is allowed to be called recursively.
*
* @param indexedRegion
* @param textSelection
* @return new region to select or null if none
*/
private Region getNewSelectionRegion2(IndexedRegion indexedRegion, ITextSelection textSelection) {
Region newRegion = null;
if (indexedRegion instanceof Node) {
Node node = (Node) indexedRegion;
Node newNode = node.getNextSibling();
if (newNode == null) {
newNode = node.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(textSelection.getOffset(), newIndexedRegion.getEndOffset() - textSelection.getOffset());
if (newNode.getNodeType() == Node.TEXT_NODE) {
newRegion = getNewSelectionRegion2(newIndexedRegion, new TextSelection(newRegion.getOffset(), newRegion.getLength()));
}
}
}
}
return newRegion;
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class StructuredSelectNextXMLActionDelegate method getCursorIndexedRegion.
protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) {
int offset = textSelection.getOffset() + textSelection.getLength() - 1;
if (offset < 0) {
offset = 0;
}
IndexedRegion indexedRegion = null;
indexedRegion = getIndexedRegion(document, offset);
return indexedRegion;
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class StructuredSelectNextXMLActionDelegate method getNewSelectionRegion.
protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
Region newRegion = null;
if (indexedRegion instanceof Node) {
Node cursorNode = (Node) indexedRegion;
// use parent node for empty text node
if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) {
cursorNode = cursorNode.getParentNode();
if (cursorNode instanceof IndexedRegion) {
indexedRegion = (IndexedRegion) cursorNode;
}
}
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)) {
newRegion = getNewSelectionRegion2(indexedRegion, textSelection);
} else {
newRegion = cursorNodeRegion;
}
}
return newRegion;
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class BaseHyperlinkDetector method getCurrentNode.
/**
* Returns the node the cursor is currently on in the document or null if no
* node is selected
*
* @param offset the current cursor offset.
* @return IDOMNode either element, doctype, text, attribute or null
*/
private IDOMNode getCurrentNode(IDocument document, int offset) {
IndexedRegion inode = null;
IStructuredModel sModel = null;
try {
sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document);
inode = sModel.getIndexedRegion(offset);
if (inode == null)
inode = sModel.getIndexedRegion(offset - 1);
} finally {
if (sModel != null)
sModel.releaseFromRead();
}
if (inode instanceof IDOMNode) {
IDOMNode node = (IDOMNode) inode;
if (node.hasAttributes()) {
node = getAttributeNode(offset, node);
}
return node;
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class SelectionConvertor method getElements.
/**
* @param model
* @param start
* @param end
* @return the most specific mapping of this text selection to
* implementors of IndexedRegion
*/
public Object[] getElements(IStructuredModel model, int start, int end) {
Object[] localSelectedStructures = null;
if (model != null) {
IndexedRegion region = model.getIndexedRegion(start);
if (region != null) {
if (end <= region.getEndOffset()) {
// single selection
localSelectedStructures = new Object[1];
localSelectedStructures[0] = region;
} else {
// multiple selection
int maxLength = model.getStructuredDocument().getLength();
List structures = new ArrayList(2);
while (region != null && region.getEndOffset() <= end && region.getEndOffset() < maxLength) {
structures.add(region);
region = model.getIndexedRegion(region.getEndOffset() + 1);
}
localSelectedStructures = structures.toArray();
}
}
}
if (localSelectedStructures == null) {
localSelectedStructures = new Object[0];
}
return localSelectedStructures;
}
Aggregations