use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class LinkedModeUI method select.
private void select() {
ITextViewer viewer = fCurrentTarget.getViewer();
if (viewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension5 = (ITextViewerExtension5) viewer;
extension5.exposeModelRange(new Region(fFramePosition.offset, fFramePosition.length));
} else if (!viewer.overlapsWithVisibleRegion(fFramePosition.offset, fFramePosition.length)) {
viewer.resetVisibleRegion();
}
viewer.revealRange(fFramePosition.offset, fFramePosition.length);
viewer.setSelectedRange(fFramePosition.offset, fFramePosition.length);
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method isVisible.
/**
* Tells whether the given region is visible in the given source viewer.
*
* @param viewer the source viewer
* @param offset the offset of the region
* @param length the length of the region
* @return <code>true</code> if visible
* @since 2.1
*/
protected static final boolean isVisible(ISourceViewer viewer, int offset, int length) {
if (viewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
IRegion overlap = extension.modelRange2WidgetRange(new Region(offset, length));
return overlap != null;
}
return viewer.overlapsWithVisibleRegion(offset, length);
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class MarkRegionTarget method isVisible.
/**
* Tells whether the given offset is visible in the given text viewer.
*
* @param viewer the text viewer
* @param offset the offset to check
* @return <code>true</code> if the given offset is visible in the given text viewer
*
* @since 2.1
*/
protected static final boolean isVisible(ITextViewer viewer, int offset) {
if (viewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
return extension.modelOffset2WidgetOffset(offset) >= 0;
}
IRegion region = viewer.getVisibleRegion();
int vOffset = region.getOffset();
return (vOffset <= offset && offset <= vOffset + region.getLength());
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class MoveLinesAction method containedByVisibleRegion.
/**
* Checks if <code>selection</code> is contained by the visible region of <code>viewer</code>.
* As a special case, a selection is considered contained even if it extends over the visible
* region, but the extension stays on a partially contained line and contains only white space.
*
* @param selection the selection to be checked
* @param viewer the viewer displaying a visible region of <code>selection</code>'s document.
* @return <code>true</code>, if <code>selection</code> is contained, <code>false</code> otherwise.
*/
private boolean containedByVisibleRegion(ITextSelection selection, ITextViewer viewer) {
int min = selection.getOffset();
int max = min + selection.getLength();
IDocument document = viewer.getDocument();
IRegion visible;
if (viewer instanceof ITextViewerExtension5)
visible = ((ITextViewerExtension5) viewer).getModelCoverage();
else
visible = viewer.getVisibleRegion();
int visOffset = visible.getOffset();
try {
if (visOffset > min) {
if (document.getLineOfOffset(visOffset) != selection.getStartLine())
return false;
if (!isWhitespace(document.get(min, visOffset - min))) {
showStatus();
return false;
}
}
int visEnd = visOffset + visible.getLength();
if (visEnd < max) {
if (document.getLineOfOffset(visEnd) != selection.getEndLine())
return false;
if (!isWhitespace(document.get(visEnd, max - visEnd))) {
showStatus();
return false;
}
}
return true;
} catch (BadLocationException e) {
}
return false;
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.
the class MoveLinesAction method runWithEvent.
/*
* @see org.eclipse.jface.action.IAction#run()
*/
@Override
public void runWithEvent(Event event) {
if (fTextViewer == null)
return;
if (!validateEditorInputState())
return;
// get involved objects
IDocument document = fTextViewer.getDocument();
if (document == null)
return;
StyledText widget = fTextViewer.getTextWidget();
if (widget == null)
return;
// get selection
ITextSelection sel = (ITextSelection) fTextViewer.getSelectionProvider().getSelection();
if (sel.isEmpty())
return;
ITextSelection skippedLine = getSkippedLine(document, sel);
if (skippedLine == null)
return;
try {
ITextSelection movingArea = getMovingSelection(document, sel, fTextViewer);
// visible area, bail out
if (!containedByVisibleRegion(movingArea, fTextViewer) || !containedByVisibleRegion(skippedLine, fTextViewer))
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 (!(fTextViewer instanceof ITextViewerExtension5))
selLength = Math.min(selLength, fTextViewer.getVisibleRegion().getOffset() + fTextViewer.getVisibleRegion().getLength() - selOffset);
else {
// TODO need to check what is necessary in the projection case
}
selectAndReveal(fTextViewer, selOffset, selLength);
} catch (BadLocationException x) {
// won't happen without concurrent modification - bail out
return;
}
}
Aggregations