use of org.eclipse.jface.text.ITypedRegion in project mylyn.docs by eclipse.
the class FastMarkupPartitionerTest method testTextileLinkWithStyle.
public void testTextileLinkWithStyle() {
IDocument document = new Document();
FastMarkupPartitioner partitioner = new FastMarkupPartitioner();
partitioner.setMarkupLanguage(new TextileLanguage());
String markup = "\"_text_\":http://example.com";
document.set(markup);
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
int[][] expected = new int[][] { //
{ 0, markup.length() } };
ITypedRegion[] partitioning = partitioner.computePartitioning(0, document.getLength(), false);
assertPartitioningAsExpected(expected, partitioning);
}
use of org.eclipse.jface.text.ITypedRegion in project mylyn.docs by eclipse.
the class CommentDamagerRepairer method getDamageRegion.
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) {
if (!documentPartitioningChanged) {
try {
IRegion lineRegion = document.getLineInformationOfOffset(event.getOffset());
int start = Math.max(lineRegion.getOffset(), partition.getOffset());
int end = event.getOffset();
if (event.getText() == null) {
end += event.getLength();
} else {
end += event.getText().length();
}
if (lineRegion.getOffset() <= end && end <= lineRegion.getOffset() + lineRegion.getLength()) {
// same line
end = lineRegion.getOffset() + lineRegion.getLength();
} else {
end = toLineEnd(end);
}
int partitionEnd = partition.getOffset() + partition.getLength();
end = Math.min(partitionEnd, end);
return new Region(start, end - start);
} catch (BadLocationException e) {
// ignore
}
}
return partition;
}
use of org.eclipse.jface.text.ITypedRegion in project n4js by eclipse.
the class SupressingMLCommentPredicate method isInsertClosingBracket.
@Override
public boolean isInsertClosingBracket(IDocument doc, int offset) throws BadLocationException {
if (offset >= 2) {
ITypedRegion prevPartition = doc.getPartition(offset - 1);
String prevPartitionType = prevPartition.getType();
if (TerminalsTokenTypeToPartitionMapper.SL_COMMENT_PARTITION.equals(prevPartitionType)) {
return false;
}
if (TokenTypeToPartitionMapper.REG_EX_PARTITION.equals(prevPartitionType)) {
return prevPartition.getLength() == 1;
}
}
return SingleLineTerminalsStrategy.DEFAULT.isInsertClosingBracket(doc, offset);
}
use of org.eclipse.jface.text.ITypedRegion in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class DamagerRepairer method getDamageRegion.
@Override
public IRegion getDamageRegion(final ITypedRegion partition, final DocumentEvent event, final boolean documentPartitioningChanged) {
if (!documentPartitioningChanged) {
try {
final IRegion info = this.fDocument.getLineInformationOfOffset(event.getOffset());
final int start = Math.max(partition.getOffset(), info.getOffset());
int end = event.getOffset() + ((event.getText() == null) ? event.getLength() : event.getText().length());
if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
end = info.getOffset() + info.getLength();
} else {
end = this.endOfLineOf(end);
}
end = Math.min(partition.getOffset() + partition.getLength(), end);
return new Region(start, end - start);
} catch (BadLocationException ex) {
}
}
return partition;
}
use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class Highlighter method lineGetStyle.
public StyleRange[] lineGetStyle(int eventLineOffset, int eventLineLength) {
StyleRange[] eventStyles = EMPTY_STYLE_RANGE;
try {
if (getDocument() == null || eventLineLength == 0) {
// getDocument() == null
// during initialization, this is sometimes called before our
// structured
// is set, in which case we set styles to be the empty style
// range
// (event.styles can not be null)
// eventLineLength == 0
// we sometimes get odd requests from the very last CRLF in
// the
// document
// it has no length, and there is no node for it!
eventStyles = EMPTY_STYLE_RANGE;
} else {
/*
* LineStyleProviders work using absolute document offsets. To
* support visible regions, adjust the requested range up to
* the full document offsets.
*/
IRegion styleRegion = getDocumentRangeFromWidgetRange(eventLineOffset, eventLineLength);
if (styleRegion != null) {
int start = styleRegion.getOffset();
int length = styleRegion.getLength();
ITypedRegion[] partitions = TextUtilities.computePartitioning(getDocument(), fPartitioning, start, length, false);
eventStyles = prepareStyleRangesArray(partitions, start, length);
/*
* If there is a subtext offset, the style ranges must be
* adjusted to the expected offsets just check if
* eventLineOffset is different than start then adjust,
* otherwise u can leave it alone unless there is special
* handling for itextviewerextension5?
*/
if (start != eventLineOffset) {
int offset = 0;
// only adjust if need to
if (!(getTextViewer() instanceof ITextViewerExtension5)) {
IRegion vr = getTextViewer().getVisibleRegion();
if (vr != null) {
offset = vr.getOffset();
}
}
adjust(eventStyles, -offset);
}
eventStyles = limitSize(eventStyles);
// for debugging only
if (DEBUG) {
if (!valid(eventStyles, eventLineOffset, eventLineLength)) {
// $NON-NLS-1$
Logger.log(Logger.WARNING, "Highlighter::lineGetStyle found invalid styles at offset " + eventLineOffset);
}
}
}
}
} catch (Exception e) {
// if ANY exception occurs during highlighting,
// just return "no highlighting"
eventStyles = EMPTY_STYLE_RANGE;
if (Debug.syntaxHighlighting) {
// $NON-NLS-1$
System.out.println("Exception during highlighting!");
}
}
return eventStyles;
}
Aggregations