use of org.eclipse.jface.text.IRegion in project eclipse.platform.text by eclipse.
the class VerticalRuler method doPaint1.
/**
* Draws the vertical ruler w/o drawing the Canvas background. Uses
* <code>ITextViewerExtension5</code> for its implementation. Will replace
* <code>doPaint(GC)</code>.
*
* @param gc the GC to draw into
*/
protected void doPaint1(GC gc) {
if (fModel == null || fTextViewer == null)
return;
IAnnotationAccessExtension annotationAccessExtension = null;
if (fAnnotationAccess instanceof IAnnotationAccessExtension)
annotationAccessExtension = (IAnnotationAccessExtension) fAnnotationAccess;
ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
StyledText textWidget = fTextViewer.getTextWidget();
fScrollPos = textWidget.getTopPixel();
Point dimension = fCanvas.getSize();
// draw Annotations
Rectangle r = new Rectangle(0, 0, 0, 0);
// loop at least once through layers.
int maxLayer = 1;
for (int layer = 0; layer < maxLayer; layer++) {
Iterator<Annotation> iter = fModel.getAnnotationIterator();
while (iter.hasNext()) {
IAnnotationPresentation annotationPresentation = null;
Annotation annotation = iter.next();
int lay = IAnnotationAccessExtension.DEFAULT_LAYER;
if (annotationAccessExtension != null)
lay = annotationAccessExtension.getLayer(annotation);
else if (annotation instanceof IAnnotationPresentation) {
annotationPresentation = (IAnnotationPresentation) annotation;
lay = annotationPresentation.getLayer();
}
// dynamically update layer maximum
maxLayer = Math.max(maxLayer, lay + 1);
if (// wrong layer: skip annotation
lay != layer)
continue;
Position position = fModel.getPosition(annotation);
if (position == null)
continue;
IRegion widgetRegion = extension.modelRange2WidgetRange(new Region(position.getOffset(), position.getLength()));
if (widgetRegion == null)
continue;
int startLine = extension.widgetLineOfWidgetOffset(widgetRegion.getOffset());
if (startLine == -1)
continue;
int endLine = extension.widgetLineOfWidgetOffset(widgetRegion.getOffset() + Math.max(widgetRegion.getLength() - 1, 0));
if (endLine == -1)
continue;
r.x = 0;
r.y = JFaceTextUtil.computeLineHeight(textWidget, 0, startLine, startLine) - fScrollPos;
r.width = dimension.x;
int lines = endLine - startLine;
r.height = JFaceTextUtil.computeLineHeight(textWidget, startLine, endLine + 1, lines + 1);
if (// annotation within visible area
r.y < dimension.y && annotationAccessExtension != null)
annotationAccessExtension.paint(annotation, gc, fCanvas, r);
else if (annotationPresentation != null)
annotationPresentation.paint(gc, fCanvas, r);
}
}
}
use of org.eclipse.jface.text.IRegion in project eclipse.platform.text by eclipse.
the class TemplateCompletionProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
// adjust offset to end of normalized selection
if (selection.getOffset() == offset)
offset = selection.getOffset() + selection.getLength();
String prefix = extractPrefix(viewer, offset);
Region region = new Region(offset - prefix.length(), prefix.length());
TemplateContext context = createContext(viewer, region);
if (context == null)
return new ICompletionProposal[0];
// name of the selection variables {line, word}_selection //$NON-NLS-1$
context.setVariable("selection", selection.getText());
Template[] templates = getTemplates(context.getContextType().getId());
List<ICompletionProposal> matches = new ArrayList<>();
for (Template template : templates) {
try {
context.getContextType().validate(template.getPattern());
} catch (TemplateException e) {
continue;
}
if (template.matches(prefix, context.getContextType().getId()))
matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
}
Collections.sort(matches, fgProposalComparator);
return matches.toArray(new ICompletionProposal[matches.size()]);
}
use of org.eclipse.jface.text.IRegion in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testFind.
@org.junit.Test
public void testFind() {
FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(fDocument);
try {
IRegion result = new Region(8, 11);
// Find case-sensitive
// $NON-NLS-1$
IRegion r = findReplaceDocumentAdapter.find(0, "TestPackage", true, true, false, false);
assertEquals(result, r);
// $NON-NLS-1$
r = findReplaceDocumentAdapter.find(0, "testpackage", true, true, false, false);
assertNull(r);
// Find non-case-sensitive
// $NON-NLS-1$
r = findReplaceDocumentAdapter.find(0, "TestPackage", true, false, false, false);
assertEquals(r, result);
// $NON-NLS-1$
r = findReplaceDocumentAdapter.find(0, "testpackage", true, false, false, false);
assertEquals(r, result);
} catch (BadLocationException e) {
Assert.assertTrue(false);
}
}
use of org.eclipse.jface.text.IRegion in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testRegexFindLinebreak3.
@Test
public void testRegexFindLinebreak3() throws Exception {
FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(fDocument);
String contents = "One\r\nTwo\r\n\r\nEnd";
fDocument.set(contents);
int two = contents.indexOf("Two");
int end = contents.indexOf("End");
IRegion region = adapter.find(0, "[a-zA-Z]+\\R", true, false, false, true);
assertEquals(new Region(0, two), region);
region = adapter.find(two, "[a-zA-Z]+\\R", true, false, false, true);
assertEquals(new Region(two, 3 + 2), region);
region = adapter.find(0, "[a-zA-Z]+\\R{2}", true, false, false, true);
assertEquals(new Region(two, end - two), region);
}
use of org.eclipse.jface.text.IRegion in project eclipse.platform.text by eclipse.
the class FindReplaceDocumentAdapterTest method testBug386751.
/**
* Test case for: https://bugs.eclipse.org/386751
*/
@Test
public void testBug386751() {
FindReplaceDocumentAdapter adapter = new FindReplaceDocumentAdapter(fDocument);
try {
IRegion result = adapter.find(0, ".", true, false, true, false);
assertNull(result);
} catch (BadLocationException e) {
Assert.assertTrue(false);
}
}
Aggregations