Skip to content

Commit

Permalink
Merge pull request #454 from groovy/issue410
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles authored Feb 5, 2018
2 parents 39cf3e0 + 166dc00 commit 3a5858c
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,16 @@ public void apply(IDocument document, char trigger, int offset) {

super.apply(document, trigger, offset);

if (getContextInformationPosition() > 0) {
if (fContextInformationPosition > 0) {
// change offset from relative to absolute
setContextInformationPosition(getContextInformationPosition() + getReplacementOffset());
}
if (fPositions != null && !fPositions.isEmpty()) {
fSelectedRegion = new Region(fPositions.get(0).getOffset(), fPositions.get(0).getLength());
setContextInformationPosition(getReplacementOffset() + fContextInformationPosition);

// coordinate editor selection with context display and linking mode
if (fPositions == null || fPositions.isEmpty()) {
fSelectedRegion = new Region(fContextInformationPosition, 0);
} else {
fSelectedRegion = new Region(fPositions.get(0).getOffset(), fPositions.get(0).getLength());
}
}
} catch (Exception e) {
GroovyContentAssist.logError(e);
Expand Down Expand Up @@ -220,8 +224,7 @@ protected String computeReplacementString() {
buffer.append(SPACE);
}

setCursorPosition(buffer.length()); // position cursor inside parentheses
setContextInformationPosition(getCursorPosition());
setContextInformationPosition(buffer.length());

if (!fPreferences.bCommandChaining)
buffer.append(RPAREN);
Expand Down Expand Up @@ -258,7 +261,7 @@ protected String computeReplacementString() {

setContextInformationPosition(buffer.length());

// now add the parameters; named parameters go first
// add the parameters; named parameters precede positional parameters
char[][] namedParameterNames = ((GroovyCompletionProposal) fProposal).getNamedParameterNames();
char[][] regularParameterNames = ((GroovyCompletionProposal) fProposal).getRegularParameterNames();
int namedCount = namedParameterNames.length, totalCount = regularParameterNames.length + namedCount;
Expand Down Expand Up @@ -436,30 +439,31 @@ public Point getSelection(IDocument document) {
return super.getSelection(document);
}

@Override
protected boolean needsLinkedMode() {
return (fPositions != null);
}

@Override
protected void setUpLinkedMode(IDocument document, char closingCharacter) {
if (getTextViewer() != null) {
try {
int baseOffset = getReplacementOffset();
LinkedModeModel model = new LinkedModeModel();
for (int i = 0; i < fPositions.size(); i += 1) {
Position position = fPositions.get(i);
// change offset from relative to absolute
position.setOffset(baseOffset + position.getOffset());
if (fPositions == null) {
LinkedPositionGroup group = new LinkedPositionGroup();
if (fProposals.size() <= i || fProposals.get(i).length < 2) {
group.addPosition(new LinkedPosition(document, position.getOffset(), position.getLength(), LinkedPositionGroup.NO_STOP));
} else {
ensurePositionCategoryInstalled(document, model);
document.addPosition(fPositionCategory, position);
group.addPosition(new ProposalPosition(document, position.getOffset(), position.getLength(), LinkedPositionGroup.NO_STOP, fProposals.get(i)));
}
group.addPosition(new LinkedPosition(document, baseOffset + fContextInformationPosition, 0));
model.addGroup(group);
} else {
for (int i = 0, n = fPositions.size(); i < n; i += 1) {
Position position = fPositions.get(i);
// change offset from relative to absolute
position.setOffset(baseOffset + position.getOffset());
LinkedPositionGroup group = new LinkedPositionGroup();
if (fProposals.size() <= i || fProposals.get(i).length <= 1) {
group.addPosition(new LinkedPosition(document, position.getOffset(), position.getLength(), LinkedPositionGroup.NO_STOP));
} else {
ensurePositionCategoryInstalled(document, model);
document.addPosition(fPositionCategory, position);
group.addPosition(new ProposalPosition(document, position.getOffset(), position.getLength(), LinkedPositionGroup.NO_STOP, fProposals.get(i)));
}
model.addGroup(group);
}
}
JavaEditor editor = getJavaEditor();
if (editor != null) {
Expand Down

0 comments on commit 3a5858c

Please sign in to comment.