public void selectionChanged( SelectionChangedEvent event) { if (event.getSelection() instanceof TextSelection) { TextSelection textSelection = ((TextSelection) event .getSelection()); _designViewer .getSynchronizer() .textSelectionChanged( textSelection.getOffset(), textSelection.getOffset() + textSelection .getLength()); } } });
/** * To see whether the textSelection start and end are on the same. * * @param model * @param textSelection * @param lookForChildren * @return */ public static boolean isSame(IStructuredModel model, TextSelection textSelection) { if (model != null && textSelection != null) { int t1 = textSelection.getOffset(); int t2 = textSelection.getLength() + t1; return model.getIndexedRegion(t1) == model.getIndexedRegion(t2); } return false; }
@Override public void run() { IXtextDocument document = editor.getDocument(); ISelection selection = editor.getSelectionProvider().getSelection(); if (selection instanceof TextSelection) { TextSelection textSelection = (TextSelection) selection; if (textSelection.getLength()==0) { IRegion region = matcher.match(document, textSelection.getOffset()); if (region != null) { if (region.getOffset()+1==textSelection.getOffset()) { editor.selectAndReveal(region.getOffset()+region.getLength(),0); } else { editor.selectAndReveal(region.getOffset()+1,0); } } } } }
/** * preExecute and postExecute is a pair. () SHOULD NOT throw any exception, * if it throw any exception, it should catch itself and return false to * indicate not continue. */ protected final boolean preExecute() { int position = 0; int length = 0; ISelection selection = _editor.getTextViewer().getSelection(); if (selection instanceof TextSelection) { position = ((TextSelection) selection).getOffset(); length = ((TextSelection) selection).getLength(); } getModel().beginRecording(this, getLabel(), position, length); getModel().aboutToChangeModel(); return true; }
public static DesignRange convertToDesignRange(IStructuredModel fModel, TextSelection textSelection) { int start = textSelection.getOffset(); int end = textSelection.getLength() + start; IDOMPosition startDomPos = EditModelQuery.getInstance() .createDomposition((IDOMModel) fModel, start, false); IDOMPosition endDomPos = EditModelQuery.getInstance() .createDomposition((IDOMModel) fModel, end, false); if (startDomPos == null) { startDomPos = endDomPos; } else if (endDomPos == null) { endDomPos = startDomPos; } if (startDomPos != null) { DesignPosition startPos = null, endPos = null; startPos = DOMPositionHelper.toDesignPosition(startDomPos); endPos = DOMPositionHelper.toDesignPosition(endDomPos); if (startPos != null) { return new DesignRange(startPos, endPos); } } return null; }
final IResource res = breakpointUtil.getBreakpointResource(xtextEditor.getEditorInput()); final URI uri = breakpointUtil.getBreakpointURI(xtextEditor.getEditorInput()); final int offset = ((TextSelection) selection).getOffset(); final int line = xtextEditor.getDocument().getLineOfOffset(offset) + 1;
int offset1 = ((TextSelection) viewer.getSelectionProvider().getSelection()).getOffset(); if (variables != null)
/** * To see if the range and text selection covered the same range. * * @param model * @param range * @param textSelection * @return */ public static boolean isSame(IStructuredModel model, DesignRange range, TextSelection textSelection) { if (model != null && range != null && textSelection != null) { int t1 = textSelection.getOffset(); int t2 = textSelection.getLength() + t1; int r1 = getIndexedRegionLocation(DOMRangeHelper.toDOMRange(range) .getStartPosition()); int r2 = getIndexedRegionLocation(DOMRangeHelper.toDOMRange(range) .getEndPosition()); return (model.getIndexedRegion(t1) == model.getIndexedRegion(r1) && // model.getIndexedRegion(t2) == model.getIndexedRegion(r2)) || (model.getIndexedRegion(t2) == model .getIndexedRegion(r1) && // model.getIndexedRegion(t1) == model.getIndexedRegion(r2)); } return false; }