Search in sources :

Example 1 with DocumentCharacterIterator

use of org.eclipse.xtext.ui.editor.model.DocumentCharacterIterator in project xtext-eclipse by eclipse.

the class AbstractWordAwareDoubleClickStrategy method findWord.

@Override
protected IRegion findWord(IDocument document, int offset) {
    try {
        IRegion line = document.getLineInformationOfOffset(offset);
        if (offset == line.getOffset() + line.getLength())
            return null;
        com.ibm.icu.text.BreakIterator breakIter = createBreakIterator();
        breakIter.setText(new DocumentCharacterIterator(document));
        int start = breakIter.preceding(offset);
        if (start == BreakIterator.DONE)
            start = line.getOffset();
        int end = breakIter.following(offset);
        if (end == BreakIterator.DONE)
            end = line.getOffset() + line.getLength();
        if (breakIter.isBoundary(offset)) {
            if (end - offset > offset - start)
                start = offset;
            else
                end = offset;
        }
        if (end == start)
            return null;
        return new Region(start, end - start);
    } catch (BadLocationException e) {
        return null;
    }
}
Also used : DocumentCharacterIterator(org.eclipse.xtext.ui.editor.model.DocumentCharacterIterator) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) BreakIterator(com.ibm.icu.text.BreakIterator) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

BreakIterator (com.ibm.icu.text.BreakIterator)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1 DocumentCharacterIterator (org.eclipse.xtext.ui.editor.model.DocumentCharacterIterator)1