/** * Provide the text selection that is needed to execute the command. Default implementation, * extend to Erlang elements selected. * * @param document text {@link IDocument} * @param selection selection affected by command (extended by extendSelection) * @return new {@link ITextSelection} with all text up to selection */ protected ITextSelection getTextSelection( final IDocument document, final ITextSelection selection) { if (getTextEditor() instanceof ErlangEditor) { final ErlangEditor erlangEditor = (ErlangEditor) getTextEditor(); final IErlModule module = erlangEditor.getModule(); if (module != null) { final int offset1 = selection.getOffset(), offset2 = offset1 + selection.getLength(); try { final IErlElement e1 = module.getElementAt(offset1); final IErlElement e2 = module.getElementAt(offset2); if (e1 instanceof ISourceReference) { final ISourceReference ref1 = (ISourceReference) e1; final ISourceRange r1 = ref1.getSourceRange(); if (e1 == e2) { return extendSelectionToWholeLines( document, new TextSelection(document, r1.getOffset(), r1.getLength())); } else if (e2 == null) { return extendSelectionToWholeLines( document, new TextSelection( document, r1.getOffset(), selection.getLength() + selection.getOffset() - r1.getOffset())); } else if (e2 instanceof ISourceReference) { final ISourceReference ref2 = (ISourceReference) e2; final ISourceRange r2 = ref2.getSourceRange(); return extendSelectionToWholeLines( document, new TextSelection( document, r1.getOffset(), r2.getOffset() - r1.getOffset() + r2.getLength())); } } } catch (final ErlModelException e) { } } } return extendSelectionToWholeLines(document, selection); }