public void NavigateTo(GraphObject graphObject) { GraphNode node = (GraphNode)graphObject; Uri file = node.Id.GetNestedValueByName <Uri>(CodeGraphNodeIdName.File); ParseItem item = node.Id.GetNestedValueByName <ParseItem>(CssGraphSchema.CssParseItem); if (file != null && item != null) { EditorExtensionsPackage.DTE.ItemOperations.OpenFile(file.LocalPath); IWpfTextView view = ProjectHelpers.GetCurentTextView(); SnapshotSpan span = new SnapshotSpan(view.TextBuffer.CurrentSnapshot, item.Start, 0); view.Caret.MoveTo(span.Start); view.ViewScroller.EnsureSpanVisible(span); } }
public void NavigateTo() { EditorExtensionsPackage.DTE.ItemOperations.OpenFile(_file); Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { var view = ProjectHelpers.GetCurentTextView(); var textBuffer = ProjectHelpers.GetCurentTextBuffer(); var span = new SnapshotSpan(textBuffer.CurrentSnapshot, _selector.Start, _selector.Length); var point = new SnapshotPoint(textBuffer.CurrentSnapshot, _selector.Start + _selector.Length); view.ViewScroller.EnsureSpanVisible(span); view.Caret.MoveTo(point); view.Selection.Select(span, false); }), DispatcherPriority.ApplicationIdle, null); }
public void UpdateSource(string innerHtml, string file, int position) { WebEssentialsPackage.DTE.ItemOperations.OpenFile(file); Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { var view = ProjectHelpers.GetCurentTextView(); var html = HtmlEditorDocument.TryFromTextView(view); if (html == null) { return; } ElementNode element; AttributeNode attribute; view.Selection.Clear(); html.HtmlEditorTree.GetPositionElement(position + 1, out element, out attribute); // HTML element if (element != null && element.Start == position) { Span span = new Span(element.InnerRange.Start, element.InnerRange.Length); string text = html.TextBuffer.CurrentSnapshot.GetText(span); if (text != innerHtml) { UpdateBuffer(innerHtml, html, span); } } // ActionLink else if (element.Start != position) { //@Html.ActionLink("Application name", "Index", "Home", null, new { @class = "brand" }) Span span = new Span(position, 100); if (position + 100 < html.TextBuffer.CurrentSnapshot.Length) { string text = html.TextBuffer.CurrentSnapshot.GetText(span); var result = Regex.Replace(text, @"^html.actionlink\(""([^""]+)""", "Html.ActionLink(\"" + innerHtml + "\"", RegexOptions.IgnoreCase); UpdateBuffer(result, html, span); } } }), DispatcherPriority.ApplicationIdle, null); }
private static void AddMetaTag(int index) { Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { var view = ProjectHelpers.GetCurentTextView(); var buffer = view.TextBuffer; EditorExtensionsPackage.DTE.UndoContext.Open("Adding <meta> viewport"); buffer.Insert(index, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />" + Environment.NewLine); view.Caret.MoveTo(new SnapshotPoint(buffer.CurrentSnapshot, index)); EditorExtensionsPackage.DTE.ExecuteCommand("Edit.FormatSelection"); EditorExtensionsPackage.DTE.UndoContext.Close(); EditorExtensionsPackage.DTE.ActiveDocument.Save(); }), DispatcherPriority.ApplicationIdle, null); }
private static void AddMetaTag(int index) { Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { var view = ProjectHelpers.GetCurentTextView(); var buffer = view.TextBuffer; using (EditorExtensionsPackage.UndoContext("Adding <meta> description")) { buffer.Insert(index, "<meta name=\"description\" content=\"The description of my page\" />" + Environment.NewLine); view.Caret.MoveTo(new SnapshotPoint(buffer.CurrentSnapshot, index + 34 + 26)); view.Selection.Select(new SnapshotSpan(buffer.CurrentSnapshot, 34 + index, 26), false); EditorExtensionsPackage.ExecuteCommand("Edit.FormatSelection"); } EditorExtensionsPackage.DTE.ActiveDocument.Save(); view.ViewScroller.EnsureSpanVisible(new SnapshotSpan(buffer.CurrentSnapshot, index, 1), EnsureSpanVisibleOptions.AlwaysCenter); }), DispatcherPriority.ApplicationIdle, null); }
public static SnapshotPoint?GetCurrentSelection(string contentType) { return(ProjectHelpers.GetCurentTextView().GetSelection(contentType)); }