diff options
author | Tor Norbye <tnorbye@google.com> | 2011-07-26 17:43:22 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-07-26 17:43:22 -0700 |
commit | 8853ecca4ab4ecc22254d1ddee92aa95b90c590e (patch) | |
tree | 47d6550ac3d9e6907d4cb02090b218af1d57fc59 /eclipse/plugins/com.android.ide.eclipse.adt | |
parent | 4acb7dd9a09af790eb019922f6e4bc8555c39cd6 (diff) | |
download | sdk-8853ecca4ab4ecc22254d1ddee92aa95b90c590e.zip sdk-8853ecca4ab4ecc22254d1ddee92aa95b90c590e.tar.gz sdk-8853ecca4ab4ecc22254d1ddee92aa95b90c590e.tar.bz2 |
Fix code completion handling for text selection
This CL fixes
18607: ADT 12 problems with xml files
The bug is that if there is a text selection and you invoke code
completion and select an alternative, the wrong number of characters
is deleted as part of the replacement.
The fix is simple: remove the code which adds in the selection count
from the replacement string, since the complete replacement count is
now already computed properly without regard for the selection (we
should -always- replace the complete value token, not just the
selection).
Most of the diffs actually pertain to new unit tests for this because
the testing infrastructure needed some changes to handle references to
selection ranges rather than just caret offsets.
There are also a couple of updates to some test goldenfiles unrelated
to this fix, which updates the golden files to reflect recent changes
like the package name of GestureOverlayViews and the @attr resource
type in completion.
Change-Id: Ie4f680f201930414457a79846f722db6efc89f93
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt')
2 files changed, 3 insertions, 26 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java index 38ab6d8..3f5a318 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidContentAssist.java @@ -45,14 +45,12 @@ import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.contentassist.CompletionProposal; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.jface.text.contentassist.IContextInformationValidator; import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.graphics.Image; import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; import org.w3c.dom.NamedNodeMap; @@ -195,7 +193,6 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { return; } - int selectionLength = getSelectionLength(viewer); int replaceLength = parent.length() - wordPrefix.length(); boolean isNew = replaceLength == 0 && nextNonspaceChar(viewer, offset) == '<'; // Special case: if we are right before the beginning of a new @@ -214,21 +211,10 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { addMatchingProposals(proposals, choices, offset, parentNode != null ? parentNode : null, wordPrefix, needTag, false /* isAttribute */, isNew, false /*isComplete*/, - selectionLength + replaceLength); + replaceLength); } } - private int getSelectionLength(ITextViewer viewer) { - // get the selection length - int selectionLength = 0; - ISelection selection = viewer.getSelectionProvider().getSelection(); - if (selection instanceof TextSelection) { - TextSelection textSelection = (TextSelection) selection; - selectionLength = textSelection.getLength(); - } - return selectionLength; - } - private void computeAttributeProposals(List<ICompletionProposal> proposals, ITextViewer viewer, int offset, String wordPrefix, UiElementNode currentUiNode, Node parentNode, Node currentNode, String parent, AttribInfo info, char nextChar) { @@ -247,7 +233,6 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { return; } - int selectionLength = getSelectionLength(viewer); int replaceLength = info.replaceLength; if (info.correctedPrefix != null) { wordPrefix = info.correctedPrefix; @@ -259,7 +244,7 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { addMatchingProposals(proposals, choices, offset, parentNode != null ? parentNode : null, wordPrefix, needTag, true /* isAttribute */, isNew, info.skipEndTag, - selectionLength + replaceLength); + replaceLength); } private char computeElementNeedTag(ITextViewer viewer, int offset, String wordPrefix) { @@ -541,20 +526,13 @@ public abstract class AndroidContentAssist implements IContentAssistProcessor { ISourceViewer viewer = mEditor.getStructuredSourceViewer(); char needTag = computeElementNeedTag(viewer, offset, wordPrefix); - // get the selection length - int selectionLength = 0; - ISelection selection = viewer.getSelectionProvider().getSelection(); - if (selection instanceof TextSelection) { - TextSelection textSelection = (TextSelection) selection; - selectionLength = textSelection.getLength(); - } int replaceLength = 0; addMatchingProposals(proposals, choices, offset, parentNode, wordPrefix, needTag, false /* isAttribute */, false /*isNew*/, false /*isComplete*/, - selectionLength + replaceLength); + replaceLength); } } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PreviewIconFactory.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PreviewIconFactory.java index ae41f84..ace5093 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PreviewIconFactory.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PreviewIconFactory.java @@ -350,7 +350,6 @@ public class PreviewIconFactory { } AdtPlugin.log(IStatus.WARNING, "Failed to render set of icons for %1$s", sb.toString()); - System.out.println(sb.toString()); if (session.getResult().getException() != null) { AdtPlugin.log(session.getResult().getException(), |