public override bool IsAvailable(IUserDataHolder cache) { IHtmlTagHeader tagHeader = GetTag(); if (tagHeader == null) { return(false); } // check if the attribute is already there (case-insensitive) return(!tagHeader.Attributes.Any(a => a.AttributeName.Equals("id", StringComparison.OrdinalIgnoreCase))); }
protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { IHtmlTagHeader tagHeader = GetTag(); if (tagHeader == null) { return(null); } // The easiest way to create an attribute is to create an HTML tag with an attribute in it // and then get the attribute from the tag. HtmlElementFactory factory = HtmlElementFactory.GetInstance(tagHeader.Language); IHtmlTag dummy = factory.CreateHtmlTag("<tag id=\"\"/>", tagHeader); ITagAttribute idAttr = dummy.Attributes.Single(); tagHeader.AddAttributeBefore(idAttr, null); // continuation to do after transaction committed return(textControl => // move cursor inside new created id attribute textControl.Caret.MoveTo(idAttr.ValueElement.GetDocumentRange().TextRange.StartOffset, CaretVisualPlacement.Generic)); }