Search in sources :

Example 1 with RegionImpl

use of org.eclipse.che.ide.api.editor.text.RegionImpl in project che by eclipse.

the class DocumentPartitioningChangedEvent method getCoverage.

/**
     * Returns the coverage of this event. This is the minimal region that contains all changed regions of all changed
     * partitionings.
     *
     * @return the coverage of this event
     */
public Region getCoverage() {
    if (fMap.isEmpty())
        return new RegionImpl(0, 0);
    int offset = -1;
    int endOffset = -1;
    Iterator<Region> e = fMap.values().iterator();
    while (e.hasNext()) {
        Region r = e.next();
        if (offset < 0 || r.getOffset() < offset)
            offset = r.getOffset();
        int end = r.getOffset() + r.getLength();
        if (end > endOffset)
            endOffset = end;
    }
    return new RegionImpl(offset, endOffset - offset);
}
Also used : Region(org.eclipse.che.ide.api.editor.text.Region) RegionImpl(org.eclipse.che.ide.api.editor.text.RegionImpl)

Example 2 with RegionImpl

use of org.eclipse.che.ide.api.editor.text.RegionImpl in project che by eclipse.

the class OrionEditorWidget method getSelectedRange.

@Override
public Region getSelectedRange() {
    final OrionSelectionOverlay selection = this.editorOverlay.getSelection();
    final int start = selection.getStart();
    final int end = selection.getEnd();
    if (start < 0 || end > this.editorOverlay.getModel().getCharCount() || start > end) {
        throw new RuntimeException("Invalid selection");
    }
    return new RegionImpl(start, end - start);
}
Also used : OrionSelectionOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionSelectionOverlay) RegionImpl(org.eclipse.che.ide.api.editor.text.RegionImpl)

Example 3 with RegionImpl

use of org.eclipse.che.ide.api.editor.text.RegionImpl in project che by eclipse.

the class ReconcilerWithAutoSave method process.

/**
     * Processes a dirty region. If the dirty region is <code>null</code> the whole document is consider being dirty. The dirty region is
     * partitioned by the document and each partition is handed over to a reconciling strategy registered for the partition's content type.
     *
     * @param dirtyRegion the dirty region to be processed
     */
protected void process(final DirtyRegion dirtyRegion) {
    Region region = dirtyRegion;
    if (region == null) {
        region = new RegionImpl(0, getDocument().getContents().length());
    }
    final List<TypedRegion> regions = computePartitioning(region.getOffset(), region.getLength());
    for (final TypedRegion r : regions) {
        final ReconcilingStrategy strategy = getReconcilingStrategy(r.getType());
        if (strategy == null) {
            continue;
        }
        if (dirtyRegion != null) {
            strategy.reconcile(dirtyRegion, r);
        } else {
            strategy.reconcile(r);
        }
    }
}
Also used : Region(org.eclipse.che.ide.api.editor.text.Region) TypedRegion(org.eclipse.che.ide.api.editor.text.TypedRegion) TypedRegion(org.eclipse.che.ide.api.editor.text.TypedRegion) RegionImpl(org.eclipse.che.ide.api.editor.text.RegionImpl)

Example 4 with RegionImpl

use of org.eclipse.che.ide.api.editor.text.RegionImpl in project che by eclipse.

the class DocumentPartitioningChangedEvent method setPartitionChange.

/**
     * Sets the specified range as changed region for the given partitioning.
     *
     * @param partitioning
     *         the partitioning
     * @param offset
     *         the region offset
     * @param length
     *         the region length
     */
public void setPartitionChange(String partitioning, int offset, int length) {
    Assert.isNotNull(partitioning);
    fMap.put(partitioning, new RegionImpl(offset, length));
}
Also used : RegionImpl(org.eclipse.che.ide.api.editor.text.RegionImpl)

Example 5 with RegionImpl

use of org.eclipse.che.ide.api.editor.text.RegionImpl in project che by eclipse.

the class FindReplaceDocumentAdapter method findReplace.

/**
     * Stateful findReplace executes a FIND, REPLACE, REPLACE_FIND or FIND_FIRST operation. In case of REPLACE and REPLACE_FIND it
     * sends a <code>DocumentEvent</code> to all registered <code>IDocumentListener</code>.
     *
     * @param startOffset
     *         document offset at which search starts this value is only used in the FIND_FIRST operation and otherwise
     *         ignored
     * @param findString
     *         the string to find this value is only used in the FIND_FIRST operation and otherwise ignored
     * @param replaceText
     *         the string to replace the current match this value is only used in the REPLACE and REPLACE_FIND
     *         operations and otherwise ignored
     * @param forwardSearch
     *         the search direction
     * @param caseSensitive
     *         indicates whether lower and upper case should be distinguished
     * @param wholeWord
     *         indicates whether the findString should be limited by white spaces as defined by Character.isWhiteSpace.
     *         Must not be used in combination with <code>regExSearch</code>.
     * @param regExSearch
     *         if <code>true</code> this operation represents a regular expression Must not be used in combination with
     *         <code>wholeWord</code>.
     * @param operationCode
     *         specifies what kind of operation is executed
     * @return the find or replace region or <code>null</code> if there was no match
     * @throws org.eclipse.che.ide.api.editor.text.BadLocationException
     *         if startOffset is an invalid document offset
     * @throws IllegalStateException
     *         if a REPLACE or REPLACE_FIND operation is not preceded by a successful FIND operation
     * @throws PatternSyntaxException
     *         if a regular expression has invalid syntax
     */
private Region findReplace(final FindReplaceOperationCode operationCode, int startOffset, String findString, String replaceText, boolean forwardSearch, boolean caseSensitive, boolean wholeWord) throws BadLocationException {
    // Validate state
    if ((operationCode == REPLACE || operationCode == REPLACE_FIND_NEXT) && (fFindReplaceState != FIND_FIRST && fFindReplaceState != FIND_NEXT))
        //$NON-NLS-1$
        throw new IllegalStateException("illegal findReplace state: cannot replace without preceding find");
    if (operationCode == FIND_FIRST) {
        if (findString == null || findString.length() == 0)
            return null;
        // Validate start offset
        if (startOffset < 0 || startOffset >= length())
            throw new BadLocationException();
        String patternFlags = "g";
        if (caseSensitive)
            patternFlags += "i";
        if (wholeWord)
            //$NON-NLS-1$ //$NON-NLS-2$
            findString = "\\b" + findString + "\\b";
        if (!wholeWord)
            findString = asRegPattern(findString);
        fFindReplaceMatchOffset = startOffset;
        regExp = RegExp.compile(findString, patternFlags);
        regExp.setLastIndex(fFindReplaceMatchOffset);
    }
    // Set state
    fFindReplaceState = operationCode;
    if (operationCode != REPLACE) {
        if (forwardSearch) {
            MatchResult matchResult = regExp.exec(String.valueOf(this));
            if (matchResult != null && matchResult.getGroupCount() > 0 && !matchResult.getGroup(0).isEmpty())
                return new RegionImpl(matchResult.getIndex(), matchResult.getGroup(0).length());
            return null;
        }
        // backward search
        regExp.setLastIndex(0);
        MatchResult matchResult = regExp.exec(String.valueOf(this));
        boolean found = matchResult != null;
        int index = -1;
        int length = -1;
        while (found && matchResult.getIndex() + matchResult.getGroup(0).length() <= fFindReplaceMatchOffset + 1) {
            index = matchResult.getIndex();
            length = matchResult.getGroup(0).length();
            regExp.setLastIndex(index + 1);
            matchResult = regExp.exec(String.valueOf(this));
            found = matchResult != null;
        }
        fFindReplaceMatchOffset = index;
        if (index > -1) {
            // must set matcher to correct position
            regExp.setLastIndex(index);
            matchResult = regExp.exec(String.valueOf(this));
            return new RegionImpl(index, length);
        }
        return null;
    }
    return null;
}
Also used : RegionImpl(org.eclipse.che.ide.api.editor.text.RegionImpl) MatchResult(com.google.gwt.regexp.shared.MatchResult) BadLocationException(org.eclipse.che.ide.api.editor.text.BadLocationException)

Aggregations

RegionImpl (org.eclipse.che.ide.api.editor.text.RegionImpl)6 BadLocationException (org.eclipse.che.ide.api.editor.text.BadLocationException)2 Region (org.eclipse.che.ide.api.editor.text.Region)2 MatchResult (com.google.gwt.regexp.shared.MatchResult)1 TypedRegion (org.eclipse.che.ide.api.editor.text.TypedRegion)1 OrionSelectionOverlay (org.eclipse.che.ide.editor.orion.client.jso.OrionSelectionOverlay)1