private void textEditor_TextArea_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Right && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && (Keyboard.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt) { string xml = _editor.Document.Text; int offset = _editor.CaretOffset; try { if (XParser.IsClosingElement(xml, offset)) { int i = xml.IndexOf('>', offset); if (i > 0) { _editor.CaretOffset = i + 1; } } else if (XParser.IsInsideElementDeclaration(xml, offset)) { if (XParser.IsInsideAttributeKey(xml, offset)) { int i = xml.IndexOf('=', offset); if (i > 0) { _editor.CaretOffset = i + 1; } } else if (XParser.IsInsideAttributeValue(xml, offset)) { int i = xml.IndexOf('>', offset); if (i > 0) { _editor.CaretOffset = i + 1; } } else { //element name int i = xml.IndexOf('>', offset); if (i > 0) { _editor.CaretOffset = i + 1; } } } else if (XParser.IsInsideComment(xml, offset)) { int i = xml.IndexOf("-->", offset); if (i > 0) { _editor.CaretOffset = i + 4; } } else { //text, goto next element int i = xml.IndexOf('<', offset); if (i > 0) { if (i == offset) { i = xml.IndexOf('>', offset); } _editor.CaretOffset = i + 1; } } } catch { Debug.Fail(""); } e.Handled = true; } }
private bool checkAttributeCompletion() { if (_schemaParser == null) { return(false); } int offset = _editor.CaretOffset; if (XParser.IsInsideElementDeclaration(_editor.Text, offset - 1)) { string element = XParser.GetElementAtCursorFuzzy(_editor.Text, offset - 1); IList <IXsdNode> all = _schemaParser.GetAllNodes(); IXsdNode node = getNodeWithName(all, element); if (node != null) { ICollection <XsdAttribute> attrs = getAttributeNames(node); if (attrs != null && attrs.Count > 0) { IList <ICompletionData> data = new List <ICompletionData>(); foreach (XsdAttribute attr in attrs) { string desc = null; if (attr.Annotation != null && attr.Annotation.Count > 0) { StringBuilder description = new StringBuilder(); foreach (string ann in attr.Annotation) { description.AppendLine(ann); } desc = description.ToString(); } data.Add(new ActionCompletionData(attr.Name, desc, (area, segment, args) => { int idxOfSpace = area.Document.Text.IndexOf(' ', offset - 1); int idxOfElementClose = area.Document.Text.IndexOf('>', offset - 1); int insertAt = Math.Min(idxOfSpace, idxOfElementClose); if (insertAt < 0) { insertAt = offset; } else { if (idxOfElementClose == insertAt) { area.Document.Insert(insertAt, " "); } insertAt = insertAt + 1; } area.Document.Insert(insertAt, attr.Name + "=\""); _editor.CaretOffset = insertAt + attr.Name.Length + 2; })); } showCompletion(data); return(true); } } } return(false); }