return;
if (!validateEditorInputState())
return;
ISourceViewer viewer= fEditor.getSourceViewer();
if (viewer == null)
return;
IDocument document= viewer.getDocument();
if (document == null)
return;
StyledText widget= viewer.getTextWidget();
if (widget == null)
return;
// get selection
Point p= viewer.getSelectedRange();
if (p == null)
return;
ITextSelection sel= new TextSelection(document, p.x, p.y);
ITextSelection skippedLine= getSkippedLine(document, sel);
if (skippedLine == null)
return;
try {
ITextSelection movingArea= getMovingSelection(document, sel, viewer);
// if either the skipped line or the moving lines are outside the widget's
// visible area, bail out
if (!containedByVisibleRegion(movingArea, viewer) || !containedByVisibleRegion(skippedLine, viewer))
return;
// get the content to be moved around: the moving (selected) area and the skipped line
String moving= movingArea.getText();
String skipped= skippedLine.getText();
if (moving == null || skipped == null || document.getLength() == 0)
return;
String delim;
String insertion;
int offset, deviation;
if (fUpwards) {
delim= document.getLineDelimiter(skippedLine.getEndLine());
if (fCopy) {
delim= TextUtilities.getDefaultLineDelimiter(document);
insertion= moving + delim;
offset= movingArea.getOffset();
deviation= 0;
} else {
Assert.isNotNull(delim);
insertion= moving + delim + skipped;
offset= skippedLine.getOffset();
deviation= -skippedLine.getLength() - delim.length();
}
} else {
delim= document.getLineDelimiter(movingArea.getEndLine());
if (fCopy) {
if (delim == null) {
delim= TextUtilities.getDefaultLineDelimiter(document);
insertion= delim + moving;
} else {
insertion= moving + delim;
}
offset= skippedLine.getOffset();
deviation= movingArea.getLength() + delim.length();
} else {
Assert.isNotNull(delim);
insertion= skipped + delim + moving;
offset= movingArea.getOffset();
deviation= skipped.length() + delim.length();
}
}
// modify the document
beginCompoundEdit();
if (fCopy) {
// fDescription= new EditDescription(offset, 0, insertion.length());
document.replace(offset, 0, insertion);
} else {
// fDescription= new EditDescription(offset, insertion.length(), insertion.length());
document.replace(offset, insertion.length(), insertion);
}
// move the selection along
int selOffset= movingArea.getOffset() + deviation;
int selLength= movingArea.getLength() + (fAddDelimiter ? delim.length() : 0);
if (! (viewer instanceof ITextViewerExtension5))
selLength= Math.min(selLength, viewer.getVisibleRegion().getOffset() + viewer.getVisibleRegion().getLength() - selOffset);
else {
// TODO need to check what is necessary in the projection case
}
selectAndReveal(viewer, selOffset, selLength);
} catch (BadLocationException x) {