Merge "[new CA] gracefully handle invalid selections"

This commit is contained in:
Stefan Oehme 2014-12-02 07:09:11 -05:00 committed by Gerrit Code Review @ Eclipse.org
commit e77154d709

View file

@ -468,11 +468,14 @@ public class ContentAssistContextFactory implements Function<ContentAssistContex
context.setOffset(completionOffset);
context.setPrefix(prefix);
int regionLength = prefix.length();
if (selection.getLength() > 0)
if (selection.getLength() > 0) {
regionLength = regionLength + selection.getLength();
}
ITextRegion region = new TextRegion(completionOffset - prefix.length(), regionLength);
if (selection.getOffset() >= 0 && selection.getLength() >= 0) {
context.setSelectedText(document.substring(selection.getOffset(), selection.getOffset() + selection.getLength()));
}
context.setReplaceRegion(region);
context.setSelectedText(document.substring(selection.getOffset(), selection.getOffset() + selection.getLength()));
context.setResource(resource);
return context;
}