public bool HandleKeyPressed(TextEditor editor, char ch)
 {
     if (editor == null)
     {
         throw new ArgumentNullException(nameof(editor));
     }
     if (char.IsWhiteSpace(ch) || editor.SelectionLength > 0)
     {
         return(false);
     }
     if (_ignoredChars.Contains(ch))
     {
         return(false);
     }
     if (XmlParser.GetXmlIdentifierBeforeIndex(editor.Document, editor.TextArea.Caret.Offset).Length > 1)
     {
         return(false);
     }
     return(CtrlSpace(editor));
 }
        public bool CtrlSpace(TextEditor editor)
        {
            if (editor == null)
            {
                throw new ArgumentNullException(nameof(editor));
            }

            var elementStartIndex = XmlParser.GetActiveElementStartIndex(editor.Document.Text, editor.TextArea.Caret.Offset);

            if (elementStartIndex <= -1)
            {
                return(false);
            }
            if (ElementStartsWith("<!", elementStartIndex, editor.Document))
            {
                return(false);
            }
            if (ElementStartsWith("<?", elementStartIndex, editor.Document))
            {
                return(false);
            }

            var defaultSchema = _schemas[0];

            var completionItems = GetCompletionItems(editor, defaultSchema);

            if (completionItems.HasItems)
            {
                completionItems.Sort();
                var identifier = XmlParser.GetXmlIdentifierBeforeIndex(editor.Document, editor.TextArea.Caret.Offset);
                completionItems.PreselectionLength = identifier.Length;
                var completionWindow = ShowCompletionWindow(editor, completionItems);
                if (completionWindow != null)
                {
                    SetCompletionWindowWidth(completionWindow, completionItems);
                }

                return(true);
            }
            return(false);
        }