Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 itemis AG ( and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at /
 package org.eclipse.xtext.ui.editor.doubleClicking;
import  org.eclipse.jface.text.BadLocationException;
import  org.eclipse.jface.text.DefaultTextDoubleClickStrategy;
import  org.eclipse.jface.text.IDocument;
import  org.eclipse.jface.text.IRegion;
import  org.eclipse.jface.text.Region;

Customized DefaultTextDoubleClickStrategy that uses a word iterator instead of a plain break iterator to tokenize the document content. It is based on the plain text content of the document, e.g. terminal tokens are not taken into account.

Sebastian Zarnekow - Initial contribution and API
public class AbstractWordAwareDoubleClickStrategy extends DefaultTextDoubleClickStrategy {
	protected IRegion findWord(IDocument documentint offset) {
		try {
			IRegion line = document.getLineInformationOfOffset(offset);
			if (offset == line.getOffset() + line.getLength())
				return null;
			breakIter.setText(new DocumentCharacterIterator(document));
			int start = breakIter.preceding(offset);
			if (start == .)
				start = line.getOffset();
			int end = breakIter.following(offset);
			if (end == .)
				end = line.getOffset() + line.getLength();
			if (breakIter.isBoundary(offset)) {
				if (end - offset > offset - start)
					start = offset;
					end = offset;
			if (end == start)
				return null;
			return new Region(startend - start);
catch (BadLocationException e) {
			return null;

a new break iterator. Defaults to an instance that does not take camel humps into account.
		return new CommonBreakIterator(false);
New to GrepCode? Check out our FAQ X