Search in sources :

Example 46 with ITypedRegion

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);
}
Also used : TextileLanguage(org.eclipse.mylyn.wikitext.textile.TextileLanguage) ITypedRegion(org.eclipse.jface.text.ITypedRegion) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 47 with ITypedRegion

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;
}
Also used : Region(org.eclipse.jface.text.Region) ITypedRegion(org.eclipse.jface.text.ITypedRegion) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 48 with ITypedRegion

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);
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion)

Example 49 with ITypedRegion

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;
}
Also used : Region(org.eclipse.jface.text.Region) ITypedRegion(org.eclipse.jface.text.ITypedRegion) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 50 with ITypedRegion

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;
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) ITypedRegion(org.eclipse.jface.text.ITypedRegion) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

ITypedRegion (org.eclipse.jface.text.ITypedRegion)129 BadLocationException (org.eclipse.jface.text.BadLocationException)59 IRegion (org.eclipse.jface.text.IRegion)42 IDocument (org.eclipse.jface.text.IDocument)21 Region (org.eclipse.jface.text.Region)19 ArrayList (java.util.ArrayList)17 TypedRegion (org.eclipse.jface.text.TypedRegion)16 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)14 Position (org.eclipse.jface.text.Position)14 TypedPosition (org.eclipse.jface.text.TypedPosition)13 List (java.util.List)11 StyleRange (org.eclipse.swt.custom.StyleRange)7 Test (org.junit.Test)7 Iterator (java.util.Iterator)6 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)6 ITextSelection (org.eclipse.jface.text.ITextSelection)5 BadPartitioningException (org.eclipse.jface.text.BadPartitioningException)4 Document (org.eclipse.jface.text.Document)4 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)4 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)4