Browse Source

fix quirks in XML completion

pull/6/merge
Siegfried Pammer 14 years ago
parent
commit
e6e380cc04
  1. 3
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopCompletionWindow.cs
  2. 10
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCodeCompletionBinding.cs
  3. 9
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCompletionItemCollection.cs
  4. 6
      src/Main/Base/Project/Src/Editor/CodeCompletion/ICompletionItemList.cs

3
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopCompletionWindow.cs

@ -123,6 +123,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
case CompletionItemListKeyResult.InsertionKey: case CompletionItemListKeyResult.InsertionKey:
this.CompletionList.RequestInsertion(e); this.CompletionList.RequestInsertion(e);
return; return;
case CompletionItemListKeyResult.Cancel:
Close();
return;
} }
} }
} }

10
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCodeCompletionBinding.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.XmlEditor
this.schemas = schemaFileAssociations.Schemas; this.schemas = schemaFileAssociations.Schemas;
} }
char[] ignoredChars = new[] { '\\', '/', '"', '\'', '=', '>' }; char[] ignoredChars = new[] { '\\', '/', '"', '\'', '=', '>', '!', '?' };
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch) public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
{ {
@ -70,6 +70,14 @@ namespace ICSharpCode.XmlEditor
public bool CtrlSpace(ITextEditor editor) public bool CtrlSpace(ITextEditor editor)
{ {
int elementStartIndex = XmlParser.GetActiveElementStartIndex(editor.Document.Text, editor.Caret.Offset);
if (elementStartIndex <= -1)
return false;
if (editor.Document.GetText(elementStartIndex, editor.Document.TextLength >= elementStartIndex + "<!".Length ? "<!".Length : editor.Document.TextLength - elementStartIndex).Equals("<!", StringComparison.OrdinalIgnoreCase))
return false;
if (editor.Document.GetText(elementStartIndex, editor.Document.TextLength >= elementStartIndex + "<?".Length ? "<?".Length : editor.Document.TextLength - elementStartIndex).Equals("<?", StringComparison.OrdinalIgnoreCase))
return false;
XmlSchemaCompletion defaultSchema = schemaFileAssociations.GetSchemaCompletion(editor.FileName); XmlSchemaCompletion defaultSchema = schemaFileAssociations.GetSchemaCompletion(editor.FileName);
XmlCompletionItemCollection completionItems = GetCompletionItems(editor, defaultSchema); XmlCompletionItemCollection completionItems = GetCompletionItems(editor, defaultSchema);

9
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCompletionItemCollection.cs

@ -15,7 +15,7 @@ namespace ICSharpCode.XmlEditor
public XmlCompletionItemCollection() public XmlCompletionItemCollection()
{ {
normalKeys.AddRange(new char[] { ' ', ':', '.', '_' }); normalKeys.AddRange(new char[] { ':', '.', '_' });
} }
public XmlCompletionItemCollection(XmlCompletionItemCollection items) public XmlCompletionItemCollection(XmlCompletionItemCollection items)
@ -120,11 +120,12 @@ namespace ICSharpCode.XmlEditor
public CompletionItemListKeyResult ProcessInput(char key) public CompletionItemListKeyResult ProcessInput(char key)
{ {
if (char.IsLetterOrDigit(key)) { if (key == '!' || key == '?')
return CompletionItemListKeyResult.Cancel;
if (char.IsLetterOrDigit(key))
return CompletionItemListKeyResult.NormalKey; return CompletionItemListKeyResult.NormalKey;
} else if (normalKeys.Contains(key)) { if (normalKeys.Contains(key))
return CompletionItemListKeyResult.NormalKey; return CompletionItemListKeyResult.NormalKey;
}
return CompletionItemListKeyResult.InsertionKey; return CompletionItemListKeyResult.InsertionKey;
} }

6
src/Main/Base/Project/Src/Editor/CodeCompletion/ICompletionItemList.cs

@ -60,7 +60,11 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
/// key. Can be used to insert whitespace (or other characters) in front of the expression /// key. Can be used to insert whitespace (or other characters) in front of the expression
/// while the completion window is open. /// while the completion window is open.
/// </summary> /// </summary>
BeforeStartKey BeforeStartKey,
/// <summary>
/// This key triggers cancellation of completion. The completion window will be closed.
/// </summary>
Cancel
} }
public class DefaultCompletionItemList : ICompletionItemList public class DefaultCompletionItemList : ICompletionItemList

Loading…
Cancel
Save